time_up 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b040cfa422a59cc1c7f2157e8f7261ed1bdc7c470da76fead75b026159f02c8
4
- data.tar.gz: 4b817578713714392dd0ab8f2694bce78c6ddf93e9b5eea16f302a5d4549c559
3
+ metadata.gz: acd14bdf2f241538214317bdc29461d543d95988458b24f17cd0ee9265ddcc0d
4
+ data.tar.gz: 3e4a9033800d1ddfa4cf40b2a9c84b0bfb5ef8c7c049d2d5801159c4d3710ad6
5
5
  SHA512:
6
- metadata.gz: 3b4fe6bff25861a0b9b76b95684e25eed9056886091556f22b70820251ea3f41b08879b2628dd8b8bee74e03720b0f39d7af87af5664c0bcaa152f7e8b88d329
7
- data.tar.gz: e0b0953129fc39ed079d3b6addebf579d8defbebcda484649a9826ff0a3e3b2383360d7d8269572746b5f5469cb076d4e6fa770ed36735f1c2fe55f319c91c5b
6
+ metadata.gz: 0bdeee99d7c5e49754786901bf8d5c9560e759a2b93d681c50f535cc039a8418a92a024779c901ad9fb4dd46fa3843486955a77e1c85c78a29897b035794814c
7
+ data.tar.gz: 135c285c49557d24bd4306fdd77ca243247a3d523e8f5d55408fef34fd2cd05c0712bcfa54420673bf5c512266177eb3c4dcc595c7924c74ca7eaea1a8bea57d
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ ruby_version: 2.4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.4
2
+
3
+ - Add `TimeUp.print_detailed_summary`
4
+
1
5
  # 0.0.3
2
6
 
3
7
  - Change the return value of TimeUp.start when passed a block to be the
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- time_up (0.0.3)
4
+ time_up (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -107,7 +107,7 @@ TimeUp.print_summary
107
107
  Which will output something like:
108
108
 
109
109
  ```
110
- TimeUp timers summary
110
+ TimeUp summary
111
111
  ========================
112
112
  :roast 0.07267s
113
113
  :veggies 0.03760s
@@ -117,10 +117,27 @@ TimeUp timers summary
117
117
  * Denotes that the timer is still active
118
118
  ```
119
119
 
120
+ And if you're calling the timers multiple times and want to see some basic
121
+ statistics in the print-out, you can call `TimeUp.print_detailed_summary`, which
122
+ will produce this:
123
+
124
+ ```
125
+ =========================================================
126
+ Name | Elapsed | Count | Min | Max | Mean
127
+ ---------------------------------------------------------
128
+ :roast | 0.08641 | 3 | 0.00127 | 0.07261 | 0.02880
129
+ :veggies | 0.03759 | 1 | 0.03759 | 0.03759 | 0.03759
130
+ :pasta | 0.01256 | 11 | 0.00000 | 0.01255 | 0.00114
131
+ :souffle* | 0.00006 | 1 | 0.00007 | 0.00007 | 0.00007
132
+
133
+ * Denotes that the timer is still active
134
+ ```
135
+
120
136
  ## API
121
137
 
122
138
  This gem defines a bunch of public methods but they're all pretty short and
123
- straightforward, so I'd encourage you to [read the code](/lib/time_up.rb).
139
+ straightforward, so when in doubt, I'd encourage you to [read the
140
+ code](/lib/time_up.rb).
124
141
 
125
142
  ### `TimeUp` module
126
143
 
@@ -128,51 +145,54 @@ straightforward, so I'd encourage you to [read the code](/lib/time_up.rb).
128
145
  if it doesn't exist)
129
146
 
130
147
  `TimeUp.start(name, [&blk])` - Starts (or restarts) a named
131
- [Timer](#timeuptimer-class). If passed with a block, will return whatever the
132
- block evaluates to. If passed without a block, it will return the timer object
148
+ [Timer](#timeuptimer-class). If passed a block, will return whatever the block
149
+ evaluates to. If called without a block, it will return the timer object
133
150
 
134
- `TimeUp.stop(name)` - Stops the named timer or raises if it's not defined
151
+ `TimeUp.stop(name)` - Stops the named timer
135
152
 
136
153
  `TimeUp.reset(name)` - Resets the named timer's elapsed time to 0, effectively
137
- restarting it if it's currently running. Raises if the timer isn't defined.
154
+ restarting it if it's currently running
138
155
 
139
156
  `TimeUp.elapsed(name)` - Returns a `Float` of the total elapsed seconds that the
140
- named timer has been running (and raises if no timer is defined with the given
141
- `name`)
157
+ named timer has been running
142
158
 
143
159
  `TimeUp.timings(name)` - Returns an array of each recorded start-to-stop
144
- duration of the timer (including the current one, if active)
160
+ duration (including the current one, if the timer is running) of the named timer
145
161
 
146
- `TimeUp.count(name)` - The number of times the timer has been started and
147
- stopped (including the current timing, if active)
162
+ `TimeUp.count(name)` - The number of times the timer has been started (including
163
+ the current timing, if the timer is running)
148
164
 
149
- `TimeUp.min(name)` - The shortest recording of the timer (including the current
150
- one, if active)
165
+ `TimeUp.min(name)` - The shortest recording by the timer
151
166
 
152
- `TimeUp.max(name)` - The longest recording of the timer (including the current
153
- one, if active)
167
+ `TimeUp.max(name)` - The longest recording by the timer
154
168
 
155
- `TimeUp.mean(name)` - The arithmetic mean of all recorded durations of the timer
169
+ `TimeUp.mean(name)` - The arithmetic mean of all recordings by the timer
156
170
 
157
- `TimeUp.total_elapsed` - Returns a `Float` of the sum of `elapsed` for all the
158
- timers you've created
171
+ `TimeUp.total_elapsed` - Returns a `Float` of the sum of `elapsed` across all
172
+ the timers you've created (note that because you can easily run multiple logical
173
+ timers simultaneously, this figure may exceed the total time spent by the
174
+ computer)
159
175
 
160
- `TimeUp.all_elapsed` - Returns a hash of timer name keys mapped to their
161
- `elapsed` values. Handy for grabbing a snapshot of the state of things at a
162
- particular point in time without stopping all your timers
176
+ `TimeUp.all_elapsed` - Returns a Hash of timer name keys mapped to their
177
+ `elapsed` values. Handy for grabbing a reference to a snapshot of the state of
178
+ things without requiring you to stop your timers
163
179
 
164
- `TimeUp.all_stats` - Returns a hash of timer name keys mapped to another
165
- hash of their basic statistics (elapsed time, number of recordings, min, max,
166
- and mean)
180
+ `TimeUp.all_stats` - Returns a Hash of timer name keys mapped to another
181
+ hash of their basic statistics (`elapsed`, `count`, `min`, `max`,
182
+ and `mean`)
167
183
 
168
- `TimeUp.active_timers` - Returns an array of all timers that are currently
169
- running. Useful for detecting cases where you might be counting the same time in
170
- multiple places simultaneously
184
+ `TimeUp.active_timers` - Returns an Array of all timers that are currently
185
+ running. Useful for detecting cases where you might be keeping time in multiple
186
+ places simultaneously
171
187
 
172
188
  `TimeUp.print_summary([io])` - Pretty-prints a multi-line summary of all your
173
- timers to standard output (or the provided
189
+ timers' total elapsed times to standard output (or the provided
174
190
  [IO](https://ruby-doc.org/core-3.0.1/IO.html))
175
191
 
192
+ `TimeUp.print_detailed_summary([io])` - Pretty-prints a multi-line summary of
193
+ all your timers' elapsed times and basic statistics to standard output (or the
194
+ provided [IO](https://ruby-doc.org/core-3.0.1/IO.html))
195
+
176
196
  `TimeUp.stop_all` - Stops all timers
177
197
 
178
198
  `TimeUp.reset_all` - Resets all timers
@@ -188,17 +208,14 @@ reference to them
188
208
 
189
209
  `elapsed` - A `Float` of the total elapsed seconds the timer has been running
190
210
 
191
- `timings` - Returns an array of each recorded start-to-stop duration of the
192
- timer (including the current one, if active)
211
+ `timings` - Returns an Array of each recorded start-to-stop duration of the
212
+ timer (including the current one, if the timer is running)
193
213
 
194
- `count` - The number of times the timer has been started and stopped (including
195
- the current timing, if active)
214
+ `count` - The number of times the timer has been started and stopped
196
215
 
197
- `min` - The shortest recording of the timer (including the current one, if
198
- active)
216
+ `min` - The shortest recording of the timer
199
217
 
200
- `max` - The longest recording of the timer (including the current one, if
201
- active)
218
+ `max` - The longest recording of the timer
202
219
 
203
220
  `mean` - The arithmetic mean of all recorded durations of the timer
204
221
 
data/lib/time_up.rb CHANGED
@@ -65,7 +65,7 @@ module TimeUp
65
65
  }
66
66
  io.puts <<~SUMMARY
67
67
 
68
- TimeUp timers summary
68
+ TimeUp summary
69
69
  ========================
70
70
  #{summaries.join("\n")}
71
71
 
@@ -73,6 +73,52 @@ module TimeUp
73
73
  SUMMARY
74
74
  end
75
75
 
76
+ def self.print_detailed_summary(io = $stdout)
77
+ cols = {
78
+ names: ["Name"],
79
+ elapsed: ["Elapsed"],
80
+ count: ["Count"],
81
+ min: ["Min"],
82
+ max: ["Max"],
83
+ mean: ["Mean"]
84
+ }
85
+ __timers.values.each { |timer|
86
+ cols[:names] << "#{timer.name.inspect}#{"*" if timer.active?}"
87
+ cols[:elapsed] << "%.5f" % timer.elapsed
88
+ cols[:count] << timer.count.to_s
89
+ cols[:min] << "%.5f" % timer.min
90
+ cols[:max] << "%.5f" % timer.max
91
+ cols[:mean] << "%.5f" % timer.mean
92
+ }
93
+
94
+ widths = cols.map { |name, vals|
95
+ [name, vals.map(&:length).max]
96
+ }.to_h
97
+
98
+ rows = cols[:names].size.times.map { |i|
99
+ if i == 0
100
+ cols.keys.map { |name|
101
+ cols[name][i].center(widths[name])
102
+ }
103
+ else
104
+ cols.keys.map { |name|
105
+ cols[name][i].ljust(widths[name])
106
+ }
107
+ end
108
+ }
109
+
110
+ full_width = widths.values.sum + (rows[0].size - 1) * 3
111
+ io.puts <<~SUMMARY
112
+
113
+ #{"=" * full_width}
114
+ #{rows[0].join(" | ")}
115
+ #{"-" * full_width}
116
+ #{rows[1..-1].map { |row| row.join(" | ") }.join("\n")}
117
+
118
+ #{"* Denotes that the timer is still active\n" if __timers.values.any?(&:active?)}
119
+ SUMMARY
120
+ end
121
+
76
122
  # Iterative methods
77
123
  def self.stop_all
78
124
  __timers.values.each(&:stop)
@@ -1,3 +1,3 @@
1
1
  module TimeUp
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-17 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".github/workflows/main.yml"
21
21
  - ".gitignore"
22
+ - ".standard.yml"
22
23
  - CHANGELOG.md
23
24
  - Gemfile
24
25
  - Gemfile.lock