time_up 0.0.4 → 0.0.5
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +22 -7
- data/lib/time_up.rb +34 -3
- data/lib/time_up/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6241f3e0e1e66bc75c67a7e7cfc76424ae4e711c5a535b87da3bdf4fa78c153
|
4
|
+
data.tar.gz: 33c77eb409cb4d4d4142207ff93a938a1124b87768047f29be0d51057c4eb5fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df9e90669ceef219dcea0bf8b21548252b97abe40b950b922f6c9ee17987494d145fdd130b5c4735a6e57daffaf5ba2d915057044f424ba68656d9b55b5f7820
|
7
|
+
data.tar.gz: ad014a9ec0471bfbc3f315b673988d7d5b5115ad29d0cc664ad63eaa81547086bff539de50e311078261c99a9616a0e683c75f9e552bf0a254d26e14d0ef702d
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,6 +11,9 @@ process and that you want to measure in aggregate. (For example, to see how
|
|
11
11
|
much time your test suite spends creating factories, truncating the database, or
|
12
12
|
invoking a critical code path.)
|
13
13
|
|
14
|
+
Here's a [blog post about time_up](https://blog.testdouble.com/posts/2021-07-19-benchmarking-your-ruby-with-time_up/) and
|
15
|
+
a [great example of when it can be useful](https://gist.github.com/searls/feee0b0eac7c329b390fed90c4714afb).
|
16
|
+
|
14
17
|
## Install
|
15
18
|
|
16
19
|
Just run `gem install time_up` or add time_up to your Gemfile:
|
@@ -122,13 +125,13 @@ statistics in the print-out, you can call `TimeUp.print_detailed_summary`, which
|
|
122
125
|
will produce this:
|
123
126
|
|
124
127
|
```
|
125
|
-
|
126
|
-
Name | Elapsed | Count | Min | Max | Mean
|
127
|
-
|
128
|
-
:roast | 0.
|
129
|
-
:veggies | 0.
|
130
|
-
:pasta | 0.
|
131
|
-
:souffle* | 0.
|
128
|
+
=============================================================================
|
129
|
+
Name | Elapsed | Count | Min | Max | Mean | Median | 95th %
|
130
|
+
-----------------------------------------------------------------------------
|
131
|
+
:roast | 0.08454 | 3 | 0.00128 | 0.07280 | 0.02818 | 0.01046 | 0.06657
|
132
|
+
:veggies | 0.03779 | 1 | 0.03779 | 0.03779 | 0.03779 | 0.03779 | 0.03779
|
133
|
+
:pasta | 0.01260 | 11 | 0.00000 | 0.01258 | 0.00115 | 0.00000 | 0.00630
|
134
|
+
:souffle* | 0.00024 | 1 | 0.00024 | 0.00025 | 0.00025 | 0.00025 | 0.00026
|
132
135
|
|
133
136
|
* Denotes that the timer is still active
|
134
137
|
```
|
@@ -168,6 +171,12 @@ the current timing, if the timer is running)
|
|
168
171
|
|
169
172
|
`TimeUp.mean(name)` - The arithmetic mean of all recordings by the timer
|
170
173
|
|
174
|
+
`TimeUp.median(name)` - The median of all recordings by the timer
|
175
|
+
|
176
|
+
`TimeUp.percentile(name, percent)` - The timing for the given
|
177
|
+
[percentile](https://en.wikipedia.org/wiki/Percentile) of all recordings by the
|
178
|
+
timer
|
179
|
+
|
171
180
|
`TimeUp.total_elapsed` - Returns a `Float` of the sum of `elapsed` across all
|
172
181
|
the timers you've created (note that because you can easily run multiple logical
|
173
182
|
timers simultaneously, this figure may exceed the total time spent by the
|
@@ -219,6 +228,12 @@ timer (including the current one, if the timer is running)
|
|
219
228
|
|
220
229
|
`mean` - The arithmetic mean of all recorded durations of the timer
|
221
230
|
|
231
|
+
`median(name)` - The median of all recordings by the timer
|
232
|
+
|
233
|
+
`percentile(name, percent)` - The timing for the given
|
234
|
+
[percentile](https://en.wikipedia.org/wiki/Percentile) of all recordings by the
|
235
|
+
timer
|
236
|
+
|
222
237
|
`active?` - Returns `true` if the timer is running
|
223
238
|
|
224
239
|
`reset(force: false)` - Resets the timer to 0 elapsed seconds. If `force` is
|
data/lib/time_up.rb
CHANGED
@@ -22,7 +22,8 @@ module TimeUp
|
|
22
22
|
:count,
|
23
23
|
:min,
|
24
24
|
:max,
|
25
|
-
:mean
|
25
|
+
:mean,
|
26
|
+
:median
|
26
27
|
].each do |method_name|
|
27
28
|
define_singleton_method method_name do |name|
|
28
29
|
__ensure_timer(name)
|
@@ -30,6 +31,11 @@ module TimeUp
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
def self.percentile(name, percentage)
|
35
|
+
__ensure_timer(name)
|
36
|
+
__timers[name].percentile(percentage)
|
37
|
+
end
|
38
|
+
|
33
39
|
# Interrogative methods
|
34
40
|
def self.total_elapsed
|
35
41
|
__timers.values.sum(&:elapsed)
|
@@ -48,7 +54,9 @@ module TimeUp
|
|
48
54
|
count: timer.count,
|
49
55
|
min: timer.min,
|
50
56
|
max: timer.max,
|
51
|
-
mean: timer.mean
|
57
|
+
mean: timer.mean,
|
58
|
+
median: timer.median,
|
59
|
+
"95th": timer.percentile(95)
|
52
60
|
}]
|
53
61
|
}.to_h
|
54
62
|
end
|
@@ -80,7 +88,9 @@ module TimeUp
|
|
80
88
|
count: ["Count"],
|
81
89
|
min: ["Min"],
|
82
90
|
max: ["Max"],
|
83
|
-
mean: ["Mean"]
|
91
|
+
mean: ["Mean"],
|
92
|
+
median: ["Median"],
|
93
|
+
"95th": ["95th %"]
|
84
94
|
}
|
85
95
|
__timers.values.each { |timer|
|
86
96
|
cols[:names] << "#{timer.name.inspect}#{"*" if timer.active?}"
|
@@ -89,6 +99,8 @@ module TimeUp
|
|
89
99
|
cols[:min] << "%.5f" % timer.min
|
90
100
|
cols[:max] << "%.5f" % timer.max
|
91
101
|
cols[:mean] << "%.5f" % timer.mean
|
102
|
+
cols[:median] << "%.5f" % timer.median
|
103
|
+
cols[:"95th"] << "%.5f" % timer.percentile(95)
|
92
104
|
}
|
93
105
|
|
94
106
|
widths = cols.map { |name, vals|
|
@@ -211,6 +223,25 @@ module TimeUp
|
|
211
223
|
times.sum / times.size
|
212
224
|
end
|
213
225
|
|
226
|
+
def median
|
227
|
+
times = timings.sort
|
228
|
+
return if times.empty?
|
229
|
+
(times[(times.size - 1) / 2] + times[times.size / 2]) / 2.0
|
230
|
+
end
|
231
|
+
|
232
|
+
def percentile(percent)
|
233
|
+
times = timings.sort
|
234
|
+
return if times.empty?
|
235
|
+
return 0 if percent <= 0
|
236
|
+
return max if percent >= 100
|
237
|
+
return times.first if times.size == 1
|
238
|
+
position = (percent / 100.0) * (times.size - 1)
|
239
|
+
|
240
|
+
partial_ratio = position - position.floor
|
241
|
+
whole, partial = times[position.floor, 2]
|
242
|
+
whole + (partial - whole) * partial_ratio
|
243
|
+
end
|
244
|
+
|
214
245
|
def timings
|
215
246
|
if active?
|
216
247
|
@past_timings + [now - @start_time]
|
data/lib/time_up/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|