benchmark-ips 2.8.4 → 2.9.3
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/{History.txt → History.md} +40 -19
- data/LICENSE +20 -0
- data/README.md +8 -28
- data/examples/advanced.rb +20 -0
- data/examples/hold.rb +41 -0
- data/examples/save.rb +50 -0
- data/examples/simple.rb +47 -0
- data/lib/benchmark/compare.rb +0 -0
- data/lib/benchmark/ips/job/entry.rb +0 -0
- data/lib/benchmark/ips/job/noop_report.rb +27 -0
- data/lib/benchmark/ips/job/stdout_report.rb +0 -0
- data/lib/benchmark/ips/job.rb +41 -22
- data/lib/benchmark/ips/noop_suite.rb +25 -0
- data/lib/benchmark/ips/report.rb +0 -0
- data/lib/benchmark/ips/share.rb +3 -1
- data/lib/benchmark/ips/stats/bootstrap.rb +0 -0
- data/lib/benchmark/ips/stats/sd.rb +0 -0
- data/lib/benchmark/ips/stats/stats_metric.rb +0 -0
- data/lib/benchmark/ips.rb +6 -13
- data/lib/benchmark/timing.rb +0 -0
- metadata +20 -38
- data/.autotest +0 -23
- data/Manifest.txt +0 -17
- data/Rakefile +0 -27
- data/test/test_benchmark_ips.rb +0 -199
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc5ffa1a7718a0e1228ff02e0473d0ca7596a0e2ed2f1837f8e7d2b6671fee80
|
|
4
|
+
data.tar.gz: 59f55a6921d0e0c2f85b37724fd1e73175bb45c83ab929476d1eecf6e20fec68
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be49c48e45aea4ca566cfb52d8e6b50eefb3e367db9733aea730af7e1191d78171c002dcb5c0308a7fe695764d5c028fcf9b088a7edd55227b7097f4b8d4a1da
|
|
7
|
+
data.tar.gz: 6c240a8f140c33a7164352be7d60a00e20aca04a91f5727d9753e6fd0aaac58e9a2bed6a3afb72ab290386dbe5bde7757e7206704e9806f53001d40091b4e346
|
data/{History.txt → History.md}
RENAMED
|
@@ -1,20 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
### 2.9.3 / 2022-01-25
|
|
2
|
+
|
|
3
|
+
* Bug fix
|
|
4
|
+
* All warmups and benchmarks must run at least once
|
|
5
|
+
|
|
6
|
+
### 2.9.2 / 2021-10-10
|
|
7
|
+
|
|
8
|
+
* Bug fix
|
|
9
|
+
* Fix a problem with certain configs of quiet mode
|
|
10
|
+
|
|
11
|
+
### 2.9.1 / 2021-05-24
|
|
12
|
+
|
|
13
|
+
* Bug fix
|
|
14
|
+
* Include all files in gem
|
|
15
|
+
|
|
16
|
+
### 2.9.0 / 2021-05-21
|
|
17
|
+
|
|
18
|
+
* Features
|
|
19
|
+
* Suite can now be set via an accessor
|
|
20
|
+
* Default SHARE_URL is now `ips.fastruby.io`, operated by Ombu Labs.
|
|
21
|
+
|
|
22
|
+
### 2.8.4 / 2020-12-03
|
|
2
23
|
|
|
3
24
|
* Bug fix
|
|
4
25
|
* Fixed hold! when results file does not exist.
|
|
5
26
|
|
|
6
|
-
|
|
27
|
+
### 2.8.3 / 2020-08-28
|
|
7
28
|
|
|
8
|
-
* Bug fix
|
|
29
|
+
* Bug fix
|
|
9
30
|
* Fixed inaccuracy caused by integer overflows.
|
|
10
31
|
|
|
11
|
-
|
|
32
|
+
### 2.8.2 / 2020-05-04
|
|
12
33
|
|
|
13
|
-
* Bug fix
|
|
34
|
+
* Bug fix
|
|
14
35
|
* Fixed problems with Manifest.txt.
|
|
15
36
|
* Empty interim results files are ignored.
|
|
16
37
|
|
|
17
|
-
|
|
38
|
+
### 2.8.0 / 2020-05-01
|
|
18
39
|
|
|
19
40
|
* Feature
|
|
20
41
|
* Allow running with empty ips block.
|
|
@@ -27,16 +48,16 @@
|
|
|
27
48
|
* Added some RDoc docs.
|
|
28
49
|
* Added some examples in examples/
|
|
29
50
|
|
|
30
|
-
|
|
51
|
+
### 2.7.2 / 2016-08-18
|
|
31
52
|
|
|
32
53
|
* 1 bug fix:
|
|
33
54
|
* Restore old accessors. Fixes #76
|
|
34
55
|
|
|
35
|
-
|
|
56
|
+
### 2.7.1 / 2016-08-08
|
|
36
57
|
|
|
37
58
|
Add missing files
|
|
38
59
|
|
|
39
|
-
|
|
60
|
+
### 2.7.0 / 2016-08-05
|
|
40
61
|
|
|
41
62
|
* 1 minor features:
|
|
42
63
|
* Add support for confidence intervals
|
|
@@ -53,9 +74,9 @@ Add missing files
|
|
|
53
74
|
* Merge pull request #67 from benoittgt/master
|
|
54
75
|
* Merge pull request #69 from chrisseaton/kalibera-confidence-intervals
|
|
55
76
|
|
|
56
|
-
|
|
77
|
+
### MISSING 2.6.0 and 2.6.1
|
|
57
78
|
|
|
58
|
-
|
|
79
|
+
### 2.5.0 / 2016-02-14
|
|
59
80
|
|
|
60
81
|
* 1 minor feature:
|
|
61
82
|
* Add iterations option.
|
|
@@ -67,12 +88,12 @@ Add missing files
|
|
|
67
88
|
* Merge pull request #58 from chrisseaton/iterations
|
|
68
89
|
* Merge pull request #60 from chrisseaton/significance
|
|
69
90
|
|
|
70
|
-
|
|
91
|
+
### 2.4.1 / 2016-02-12
|
|
71
92
|
|
|
72
93
|
* 1 bug fix:
|
|
73
94
|
* Add missing files to gem
|
|
74
95
|
|
|
75
|
-
|
|
96
|
+
### 2.4.0 / 2016-02-12
|
|
76
97
|
|
|
77
98
|
* 1 minor features
|
|
78
99
|
* Add support for hold! and independent invocations.
|
|
@@ -107,7 +128,7 @@ Add missing files
|
|
|
107
128
|
* Merge pull request #56 from chrisseaton/independence
|
|
108
129
|
* Merge pull request #57 from chrisseaton/tighten-loop
|
|
109
130
|
|
|
110
|
-
|
|
131
|
+
### 2.3.0 / 2015-07-20
|
|
111
132
|
|
|
112
133
|
* 2 minor features:
|
|
113
134
|
* Support keyword arguments
|
|
@@ -121,7 +142,7 @@ Add missing files
|
|
|
121
142
|
* Merge pull request #42 from kbrock/newer_travis
|
|
122
143
|
* Merge pull request #43 from kbrock/non_to_s_labels
|
|
123
144
|
|
|
124
|
-
|
|
145
|
+
### 2.2.0 / 2015-05-09
|
|
125
146
|
|
|
126
147
|
* 1 minor features:
|
|
127
148
|
* Fix quiet mode
|
|
@@ -145,7 +166,7 @@ Add missing files
|
|
|
145
166
|
* Merge pull request #29 from JuanitoFatas/feature/json-export
|
|
146
167
|
* Merge pull request #26 from JuanitoFatas/feature/takes-symbol-as-report-parameter
|
|
147
168
|
|
|
148
|
-
|
|
169
|
+
### 2.1.1 / 2015-01-12
|
|
149
170
|
|
|
150
171
|
* 1 minor fix:
|
|
151
172
|
* Don't send label through printf so that % work directly
|
|
@@ -159,7 +180,7 @@ Add missing files
|
|
|
159
180
|
* 1 PR merged:
|
|
160
181
|
* Merge pull request #24 from zzak/simple-format-result-description
|
|
161
182
|
|
|
162
|
-
|
|
183
|
+
### 2.1.0 / 2014-11-10
|
|
163
184
|
|
|
164
185
|
* Documentation changes:
|
|
165
186
|
* Many documentation fixes by Juanito Fatas!
|
|
@@ -170,7 +191,7 @@ Add missing files
|
|
|
170
191
|
* Formatting of large values improved (human vs raw mode)
|
|
171
192
|
* Contributed by Charles Oliver Nutter
|
|
172
193
|
|
|
173
|
-
|
|
194
|
+
### 2.0.0 / 2014-06-18
|
|
174
195
|
|
|
175
196
|
* The 'Davy Stevenson' release!
|
|
176
197
|
* Codename: Springtime Hummingbird Dance
|
|
@@ -188,7 +209,7 @@ Add missing files
|
|
|
188
209
|
* Zachary Scott
|
|
189
210
|
* schneems (Richard Schneeman)
|
|
190
211
|
|
|
191
|
-
|
|
212
|
+
### 1.0.0 / 2012-03-23
|
|
192
213
|
|
|
193
214
|
* 1 major enhancement
|
|
194
215
|
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2015 Evan Phoenix
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -186,11 +186,15 @@ end
|
|
|
186
186
|
|
|
187
187
|
### Online sharing
|
|
188
188
|
|
|
189
|
-
If you want to share
|
|
190
|
-
with `SHARE=1` argument.
|
|
191
|
-
|
|
189
|
+
If you want to quickly share your benchmark result with others, run you benchmark
|
|
190
|
+
with `SHARE=1` argument. For example: `SHARE=1 ruby my_benchmark.rb`.
|
|
191
|
+
|
|
192
|
+
Result will be sent to [benchmark.fyi](https://ips.fastruby.io/) and benchmark-ips
|
|
192
193
|
will display the link to share the benchmark's result.
|
|
193
194
|
|
|
195
|
+
If you want to run your own instance of [benchmark.fyi](https://github.com/evanphx/benchmark.fyi)
|
|
196
|
+
and share it to that instance, you can do this: `SHARE_URL=https://ips.example.com ruby my_benchmark.rb`
|
|
197
|
+
|
|
194
198
|
### Advanced Statistics
|
|
195
199
|
|
|
196
200
|
By default, the margin of error shown is plus-minus one standard deviation. If
|
|
@@ -227,7 +231,7 @@ Benchmark.ips do |x|
|
|
|
227
231
|
|
|
228
232
|
x.stats = :bootstrap
|
|
229
233
|
x.confidence = 95
|
|
230
|
-
|
|
234
|
+
|
|
231
235
|
# confidence is 95% by default, so it can be omitted
|
|
232
236
|
|
|
233
237
|
end
|
|
@@ -250,27 +254,3 @@ After checking out the source, run:
|
|
|
250
254
|
This task will install any missing dependencies, run the tests/specs,
|
|
251
255
|
and generate the RDoc.
|
|
252
256
|
|
|
253
|
-
## LICENSE:
|
|
254
|
-
|
|
255
|
-
(The MIT License)
|
|
256
|
-
|
|
257
|
-
Copyright (c) 2015 Evan Phoenix
|
|
258
|
-
|
|
259
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
260
|
-
a copy of this software and associated documentation files (the
|
|
261
|
-
'Software'), to deal in the Software without restriction, including
|
|
262
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
263
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
264
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
265
|
-
the following conditions:
|
|
266
|
-
|
|
267
|
-
The above copyright notice and this permission notice shall be
|
|
268
|
-
included in all copies or substantial portions of the Software.
|
|
269
|
-
|
|
270
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
271
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
272
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
273
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
274
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
275
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
276
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'benchmark/ips'
|
|
4
|
+
|
|
5
|
+
Benchmark.ips do |x|
|
|
6
|
+
|
|
7
|
+
# Use bootstrap confidence intervals
|
|
8
|
+
x.stats = :bootstrap
|
|
9
|
+
|
|
10
|
+
# Set confidence to 95%
|
|
11
|
+
x.confidence = 95
|
|
12
|
+
|
|
13
|
+
# Run multiple iterations for better warmup
|
|
14
|
+
x.iterations = 3
|
|
15
|
+
|
|
16
|
+
x.report("mul") { 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 }
|
|
17
|
+
x.report("pow") { 2 ** 8 }
|
|
18
|
+
|
|
19
|
+
x.compare!
|
|
20
|
+
end
|
data/examples/hold.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# example to explain hold! usage https://github.com/evanphx/benchmark-ips/issues/85
|
|
3
|
+
# The hold! feature expects to be run twice, generally with different Rubys.
|
|
4
|
+
# hold! can also be used to compare modules changes which impact the run time
|
|
5
|
+
# RUN_1: ruby examples/hold.rb
|
|
6
|
+
# Warming up --------------------------------------
|
|
7
|
+
# without 172.168k i/100ms
|
|
8
|
+
# Calculating -------------------------------------
|
|
9
|
+
# without 2.656M (± 3.3%) i/s - 13.429M in 5.062098s
|
|
10
|
+
#
|
|
11
|
+
# RUN_2: WITH_MODULE=true ruby examples/hold.rb
|
|
12
|
+
# Warming up --------------------------------------
|
|
13
|
+
# with 92.087k i/100ms
|
|
14
|
+
# Calculating -------------------------------------
|
|
15
|
+
# with 1.158M (± 1.4%) i/s - 5.801M in 5.010084s
|
|
16
|
+
#
|
|
17
|
+
# Comparison:
|
|
18
|
+
# without: 2464721.3 i/s
|
|
19
|
+
# with: 1158179.6 i/s - 2.13x slower
|
|
20
|
+
require 'benchmark/ips'
|
|
21
|
+
|
|
22
|
+
Benchmark.ips do |x|
|
|
23
|
+
x.report('without') do
|
|
24
|
+
'Bruce'.inspect
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if ENV['WITH_MODULE'] == 'true'
|
|
28
|
+
class String
|
|
29
|
+
def inspect
|
|
30
|
+
result = %w[Bruce Wayne is Batman]
|
|
31
|
+
result.join(' ')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
x.report('with') do
|
|
37
|
+
'Bruce'.inspect
|
|
38
|
+
end
|
|
39
|
+
x.hold! 'temp_results'
|
|
40
|
+
x.compare!
|
|
41
|
+
end
|
data/examples/save.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# example to explain save!
|
|
4
|
+
# The save! feature expects to be run twice, generally with different Rubys.
|
|
5
|
+
# save! can also be used to compare modules changes which impact the run time
|
|
6
|
+
#
|
|
7
|
+
# If you're comparing ruby versions, Just use the version in the label
|
|
8
|
+
#
|
|
9
|
+
# x.report("ruby #{RUBY_VERSION}") { 'Bruce'.inspect }
|
|
10
|
+
#
|
|
11
|
+
# Or use a hash
|
|
12
|
+
#
|
|
13
|
+
# x.report("version" => RUBY_VERSION, "method" => 'bruce') { 'Bruce'.inspect }
|
|
14
|
+
#
|
|
15
|
+
# RUN_1: SAVE_FILE='run1.out' ruby examples/hold.rb
|
|
16
|
+
# Warming up --------------------------------------
|
|
17
|
+
# without 172.168k i/100ms
|
|
18
|
+
# Calculating -------------------------------------
|
|
19
|
+
# without 2.656M (± 3.3%) i/s - 13.429M in 5.062098s
|
|
20
|
+
#
|
|
21
|
+
# RUN_2: SAVE_FILE='run1.out' WITH_MODULE=true ruby examples/hold.rb
|
|
22
|
+
# Warming up --------------------------------------
|
|
23
|
+
# with 92.087k i/100ms
|
|
24
|
+
# Calculating -------------------------------------
|
|
25
|
+
# with 1.158M (± 1.4%) i/s - 5.801M in 5.010084s
|
|
26
|
+
#
|
|
27
|
+
# Comparison:
|
|
28
|
+
# without: 2464721.3 i/s
|
|
29
|
+
# with: 1158179.6 i/s - 2.13x slower
|
|
30
|
+
# CLEANUP: rm run1.out
|
|
31
|
+
|
|
32
|
+
require 'benchmark/ips'
|
|
33
|
+
|
|
34
|
+
Benchmark.ips do |x|
|
|
35
|
+
x.report(ENV['WITH_MODULE'] == 'true' ? 'with' : 'without') do
|
|
36
|
+
'Bruce'.inspect
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if ENV['WITH_MODULE'] == 'true'
|
|
40
|
+
class String
|
|
41
|
+
def inspect
|
|
42
|
+
result = %w[Bruce Wayne is Batman]
|
|
43
|
+
result.join(' ')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
x.save! ENV['SAVE_FILE'] if ENV['SAVE_FILE']
|
|
49
|
+
x.compare!
|
|
50
|
+
end
|
data/examples/simple.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'benchmark/ips'
|
|
4
|
+
|
|
5
|
+
Benchmark.ips do |x|
|
|
6
|
+
|
|
7
|
+
# Configure the number of seconds used during
|
|
8
|
+
# the warmup phase and calculation phase
|
|
9
|
+
x.config(:time => 5, :warmup => 2)
|
|
10
|
+
|
|
11
|
+
# These parameters can also be configured this way
|
|
12
|
+
x.time = 5
|
|
13
|
+
x.warmup = 2
|
|
14
|
+
|
|
15
|
+
# Typical mode, runs the block as many times as it can
|
|
16
|
+
x.report("addition") { 1 + 2 }
|
|
17
|
+
|
|
18
|
+
# To reduce overhead, the number of iterations is passed in
|
|
19
|
+
# and the block must run the code the specific number of times.
|
|
20
|
+
# Used for when the workload is very small and any overhead
|
|
21
|
+
# introduces incorrectable errors.
|
|
22
|
+
x.report(:addition2) do |times|
|
|
23
|
+
i = 0
|
|
24
|
+
while i < times
|
|
25
|
+
1 + 2
|
|
26
|
+
i += 1
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# To reduce overhead even more, grafts the code given into
|
|
31
|
+
# the loop that performs the iterations internally to reduce
|
|
32
|
+
# overhead. Typically not needed, use the |times| form instead.
|
|
33
|
+
x.report("addition3", "1 + 2")
|
|
34
|
+
|
|
35
|
+
# Really long labels should be formatted correctly
|
|
36
|
+
x.report("addition-test-long-label") { 1 + 2 }
|
|
37
|
+
|
|
38
|
+
x.compare!
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
puts <<-EOD
|
|
42
|
+
Typical results will show addition2 & addition3 to be the most performant, and
|
|
43
|
+
they should perform reasonably similarly. You should see addition and
|
|
44
|
+
addition-test-long-label to perform very similarly to each other (as they are
|
|
45
|
+
running the same test, just with different labels), and they should both run in
|
|
46
|
+
the neighborhood of 3.5 times slower than addition2 and addition3."
|
|
47
|
+
EOD
|
data/lib/benchmark/compare.rb
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Benchmark
|
|
2
|
+
module IPS
|
|
3
|
+
class Job
|
|
4
|
+
class NoopReport
|
|
5
|
+
def start_warming
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def start_running
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def footer
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def warming(a, b)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def warmup_stats(a, b)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_report(a, b)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
alias_method :running, :warming
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
File without changes
|
data/lib/benchmark/ips/job.rb
CHANGED
|
@@ -51,16 +51,20 @@ module Benchmark
|
|
|
51
51
|
# @return [Integer]
|
|
52
52
|
attr_accessor :confidence
|
|
53
53
|
|
|
54
|
+
# Silence output
|
|
55
|
+
# @return [Boolean]
|
|
56
|
+
attr_reader :quiet
|
|
57
|
+
|
|
58
|
+
# Suite
|
|
59
|
+
# @return [Benchmark::IPS::NoopSuite]
|
|
60
|
+
attr_reader :suite
|
|
61
|
+
|
|
54
62
|
# Instantiate the Benchmark::IPS::Job.
|
|
55
|
-
# @option opts [Benchmark::Suite] (nil) :suite Specify Benchmark::Suite.
|
|
56
|
-
# @option opts [Boolean] (false) :quiet Suppress the printing of information.
|
|
57
63
|
def initialize opts={}
|
|
58
|
-
@suite = opts[:suite] || nil
|
|
59
|
-
@stdout = opts[:quiet] ? nil : StdoutReport.new
|
|
60
64
|
@list = []
|
|
61
|
-
@compare = false
|
|
62
65
|
@run_single = false
|
|
63
66
|
@json_path = false
|
|
67
|
+
@compare = false
|
|
64
68
|
@held_path = nil
|
|
65
69
|
@held_results = nil
|
|
66
70
|
|
|
@@ -75,6 +79,8 @@ module Benchmark
|
|
|
75
79
|
# Default statistical model
|
|
76
80
|
@stats = :sd
|
|
77
81
|
@confidence = 95
|
|
82
|
+
|
|
83
|
+
self.quiet = false
|
|
78
84
|
end
|
|
79
85
|
|
|
80
86
|
# Job configuration options, set +@warmup+ and +@time+.
|
|
@@ -88,6 +94,20 @@ module Benchmark
|
|
|
88
94
|
@iterations = opts[:iterations] if opts[:iterations]
|
|
89
95
|
@stats = opts[:stats] if opts[:stats]
|
|
90
96
|
@confidence = opts[:confidence] if opts[:confidence]
|
|
97
|
+
self.quiet = opts[:quiet] if opts.key?(:quiet)
|
|
98
|
+
self.suite = opts[:suite]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def quiet=(val)
|
|
102
|
+
@stdout = reporter(quiet: val)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def suite=(suite)
|
|
106
|
+
@suite = suite || Benchmark::IPS::NoopSuite.new
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def reporter(quiet:)
|
|
110
|
+
quiet ? NoopReport.new : StdoutReport.new
|
|
91
111
|
end
|
|
92
112
|
|
|
93
113
|
# Return true if job needs to be compared.
|
|
@@ -223,19 +243,19 @@ module Benchmark
|
|
|
223
243
|
|
|
224
244
|
def run
|
|
225
245
|
if @warmup && @warmup != 0 then
|
|
226
|
-
@stdout.start_warming
|
|
246
|
+
@stdout.start_warming
|
|
227
247
|
@iterations.times do
|
|
228
248
|
run_warmup
|
|
229
249
|
end
|
|
230
250
|
end
|
|
231
251
|
|
|
232
|
-
@stdout.start_running
|
|
252
|
+
@stdout.start_running
|
|
233
253
|
|
|
234
254
|
@iterations.times do |n|
|
|
235
255
|
run_benchmark
|
|
236
256
|
end
|
|
237
257
|
|
|
238
|
-
@stdout.footer
|
|
258
|
+
@stdout.footer
|
|
239
259
|
end
|
|
240
260
|
|
|
241
261
|
# Run warmup.
|
|
@@ -243,8 +263,8 @@ module Benchmark
|
|
|
243
263
|
@list.each do |item|
|
|
244
264
|
next if run_single? && @held_results && @held_results.key?(item.label)
|
|
245
265
|
|
|
246
|
-
@suite.warming item.label, @warmup
|
|
247
|
-
@stdout.warming item.label, @warmup
|
|
266
|
+
@suite.warming item.label, @warmup
|
|
267
|
+
@stdout.warming item.label, @warmup
|
|
248
268
|
|
|
249
269
|
Timing.clean_env
|
|
250
270
|
|
|
@@ -256,9 +276,7 @@ module Benchmark
|
|
|
256
276
|
target = Timing.add_second before, @warmup / 2.0
|
|
257
277
|
|
|
258
278
|
cycles = 1
|
|
259
|
-
|
|
260
|
-
warmup_time_us = 0.0
|
|
261
|
-
while Timing.now + warmup_time_us * 2 < target
|
|
279
|
+
begin
|
|
262
280
|
t0 = Timing.now
|
|
263
281
|
item.call_times cycles
|
|
264
282
|
t1 = Timing.now
|
|
@@ -269,7 +287,7 @@ module Benchmark
|
|
|
269
287
|
# then exit the loop to avoid overflows and start the 100ms warmup runs
|
|
270
288
|
break if cycles >= POW_2_30
|
|
271
289
|
cycles *= 2
|
|
272
|
-
end
|
|
290
|
+
end while Timing.now + warmup_time_us * 2 < target
|
|
273
291
|
|
|
274
292
|
cycles = cycles_per_100ms warmup_time_us, warmup_iter
|
|
275
293
|
@timing[item] = cycles
|
|
@@ -280,8 +298,8 @@ module Benchmark
|
|
|
280
298
|
item.call_times cycles
|
|
281
299
|
end
|
|
282
300
|
|
|
283
|
-
@stdout.warmup_stats warmup_time_us, @timing[item]
|
|
284
|
-
@suite.warmup_stats warmup_time_us, @timing[item]
|
|
301
|
+
@stdout.warmup_stats warmup_time_us, @timing[item]
|
|
302
|
+
@suite.warmup_stats warmup_time_us, @timing[item]
|
|
285
303
|
|
|
286
304
|
break if run_single?
|
|
287
305
|
end
|
|
@@ -292,8 +310,8 @@ module Benchmark
|
|
|
292
310
|
@list.each do |item|
|
|
293
311
|
next if run_single? && @held_results && @held_results.key?(item.label)
|
|
294
312
|
|
|
295
|
-
@suite.running item.label, @time
|
|
296
|
-
@stdout.running item.label, @time
|
|
313
|
+
@suite.running item.label, @time
|
|
314
|
+
@stdout.running item.label, @time
|
|
297
315
|
|
|
298
316
|
Timing.clean_env
|
|
299
317
|
|
|
@@ -306,7 +324,8 @@ module Benchmark
|
|
|
306
324
|
|
|
307
325
|
target = Timing.add_second Timing.now, @time
|
|
308
326
|
|
|
309
|
-
|
|
327
|
+
begin
|
|
328
|
+
before = Timing.now
|
|
310
329
|
item.call_times cycles
|
|
311
330
|
after = Timing.now
|
|
312
331
|
|
|
@@ -318,7 +337,7 @@ module Benchmark
|
|
|
318
337
|
iter += cycles
|
|
319
338
|
|
|
320
339
|
measurements_us << iter_us
|
|
321
|
-
end
|
|
340
|
+
end while Timing.now < target
|
|
322
341
|
|
|
323
342
|
final_time = before
|
|
324
343
|
|
|
@@ -334,8 +353,8 @@ module Benchmark
|
|
|
334
353
|
rep.show_total_time!
|
|
335
354
|
end
|
|
336
355
|
|
|
337
|
-
@stdout.add_report rep, caller(1).first
|
|
338
|
-
@suite.add_report rep, caller(1).first
|
|
356
|
+
@stdout.add_report rep, caller(1).first
|
|
357
|
+
@suite.add_report rep, caller(1).first
|
|
339
358
|
|
|
340
359
|
break if run_single?
|
|
341
360
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Benchmark
|
|
2
|
+
module IPS
|
|
3
|
+
class NoopSuite
|
|
4
|
+
def start_warming
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def start_running
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def footer
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def warming(a, b)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def warmup_stats(a, b)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def add_report(a, b)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
alias_method :running, :warming
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/benchmark/ips/report.rb
CHANGED
|
File without changes
|
data/lib/benchmark/ips/share.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'net/http'
|
|
2
4
|
require 'net/https'
|
|
3
5
|
require 'json'
|
|
@@ -5,7 +7,7 @@ require 'json'
|
|
|
5
7
|
module Benchmark
|
|
6
8
|
module IPS
|
|
7
9
|
class Share
|
|
8
|
-
DEFAULT_URL = "https://
|
|
10
|
+
DEFAULT_URL = "https://ips.fastruby.io"
|
|
9
11
|
def initialize(report, job)
|
|
10
12
|
@report = report
|
|
11
13
|
@job = job
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/lib/benchmark/ips.rb
CHANGED
|
@@ -5,8 +5,10 @@ require 'benchmark/ips/stats/stats_metric'
|
|
|
5
5
|
require 'benchmark/ips/stats/sd'
|
|
6
6
|
require 'benchmark/ips/stats/bootstrap'
|
|
7
7
|
require 'benchmark/ips/report'
|
|
8
|
+
require 'benchmark/ips/noop_suite'
|
|
8
9
|
require 'benchmark/ips/job/entry'
|
|
9
10
|
require 'benchmark/ips/job/stdout_report'
|
|
11
|
+
require 'benchmark/ips/job/noop_report'
|
|
10
12
|
require 'benchmark/ips/job'
|
|
11
13
|
|
|
12
14
|
# Performance benchmarking library
|
|
@@ -16,10 +18,10 @@ module Benchmark
|
|
|
16
18
|
module IPS
|
|
17
19
|
|
|
18
20
|
# Benchmark-ips Gem version.
|
|
19
|
-
VERSION = "2.
|
|
21
|
+
VERSION = "2.9.3"
|
|
20
22
|
|
|
21
23
|
# CODENAME of current version.
|
|
22
|
-
CODENAME = "
|
|
24
|
+
CODENAME = "Sleepy Sasquatch"
|
|
23
25
|
|
|
24
26
|
# Measure code in block, each code's benchmarked result will display in
|
|
25
27
|
# iteration per second with standard deviation in given time.
|
|
@@ -33,23 +35,14 @@ module Benchmark
|
|
|
33
35
|
time, warmup, quiet = args
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
suite = nil
|
|
37
|
-
|
|
38
38
|
sync, $stdout.sync = $stdout.sync, true
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
suite = Benchmark::Suite.current
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
quiet ||= (suite && suite.quiet?)
|
|
45
|
-
|
|
46
|
-
job = Job.new({:suite => suite,
|
|
47
|
-
:quiet => quiet
|
|
48
|
-
})
|
|
40
|
+
job = Job.new
|
|
49
41
|
|
|
50
42
|
job_opts = {}
|
|
51
43
|
job_opts[:time] = time unless time.nil?
|
|
52
44
|
job_opts[:warmup] = warmup unless warmup.nil?
|
|
45
|
+
job_opts[:quiet] = quiet unless quiet.nil?
|
|
53
46
|
|
|
54
47
|
job.config job_opts
|
|
55
48
|
|
data/lib/benchmark/timing.rb
CHANGED
|
File without changes
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: benchmark-ips
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.9.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Phoenix
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -16,80 +16,62 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '5.
|
|
19
|
+
version: '5.4'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '5.
|
|
26
|
+
version: '5.4'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rdoc
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '4.0'
|
|
34
|
-
- - "<"
|
|
35
|
-
- !ruby/object:Gem::Version
|
|
36
|
-
version: '7'
|
|
37
|
-
type: :development
|
|
38
|
-
prerelease: false
|
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
-
requirements:
|
|
41
|
-
- - ">="
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
version: '4.0'
|
|
44
|
-
- - "<"
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '7'
|
|
47
|
-
- !ruby/object:Gem::Dependency
|
|
48
|
-
name: hoe
|
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
|
50
30
|
requirements:
|
|
51
31
|
- - "~>"
|
|
52
32
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '
|
|
33
|
+
version: '4.0'
|
|
54
34
|
type: :development
|
|
55
35
|
prerelease: false
|
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
37
|
requirements:
|
|
58
38
|
- - "~>"
|
|
59
39
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '
|
|
61
|
-
description:
|
|
40
|
+
version: '4.0'
|
|
41
|
+
description: A iterations per second enhancement to Benchmark.
|
|
62
42
|
email:
|
|
63
43
|
- evan@phx.io
|
|
64
44
|
executables: []
|
|
65
45
|
extensions: []
|
|
66
46
|
extra_rdoc_files:
|
|
67
|
-
- History.
|
|
68
|
-
-
|
|
47
|
+
- History.md
|
|
48
|
+
- LICENSE
|
|
69
49
|
- README.md
|
|
70
50
|
files:
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
- Manifest.txt
|
|
51
|
+
- History.md
|
|
52
|
+
- LICENSE
|
|
74
53
|
- README.md
|
|
75
|
-
-
|
|
54
|
+
- examples/advanced.rb
|
|
55
|
+
- examples/hold.rb
|
|
56
|
+
- examples/save.rb
|
|
57
|
+
- examples/simple.rb
|
|
76
58
|
- lib/benchmark/compare.rb
|
|
77
59
|
- lib/benchmark/ips.rb
|
|
78
60
|
- lib/benchmark/ips/job.rb
|
|
79
61
|
- lib/benchmark/ips/job/entry.rb
|
|
62
|
+
- lib/benchmark/ips/job/noop_report.rb
|
|
80
63
|
- lib/benchmark/ips/job/stdout_report.rb
|
|
64
|
+
- lib/benchmark/ips/noop_suite.rb
|
|
81
65
|
- lib/benchmark/ips/report.rb
|
|
82
66
|
- lib/benchmark/ips/share.rb
|
|
83
67
|
- lib/benchmark/ips/stats/bootstrap.rb
|
|
84
68
|
- lib/benchmark/ips/stats/sd.rb
|
|
85
69
|
- lib/benchmark/ips/stats/stats_metric.rb
|
|
86
70
|
- lib/benchmark/timing.rb
|
|
87
|
-
- test/test_benchmark_ips.rb
|
|
88
71
|
homepage: https://github.com/evanphx/benchmark-ips
|
|
89
72
|
licenses:
|
|
90
73
|
- MIT
|
|
91
|
-
metadata:
|
|
92
|
-
homepage_uri: https://github.com/evanphx/benchmark-ips
|
|
74
|
+
metadata: {}
|
|
93
75
|
post_install_message:
|
|
94
76
|
rdoc_options:
|
|
95
77
|
- "--main"
|
|
@@ -107,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
89
|
- !ruby/object:Gem::Version
|
|
108
90
|
version: '0'
|
|
109
91
|
requirements: []
|
|
110
|
-
rubygems_version: 3.
|
|
92
|
+
rubygems_version: 3.2.26
|
|
111
93
|
signing_key:
|
|
112
94
|
specification_version: 4
|
|
113
|
-
summary:
|
|
95
|
+
summary: A iterations per second enhancement to Benchmark.
|
|
114
96
|
test_files: []
|
data/.autotest
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# -*- ruby -*-
|
|
2
|
-
|
|
3
|
-
require 'autotest/restart'
|
|
4
|
-
|
|
5
|
-
# Autotest.add_hook :initialize do |at|
|
|
6
|
-
# at.extra_files << "../some/external/dependency.rb"
|
|
7
|
-
#
|
|
8
|
-
# at.libs << ":../some/external"
|
|
9
|
-
#
|
|
10
|
-
# at.add_exception 'vendor'
|
|
11
|
-
#
|
|
12
|
-
# at.add_mapping(/dependency.rb/) do |f, _|
|
|
13
|
-
# at.files_matching(/test_.*rb$/)
|
|
14
|
-
# end
|
|
15
|
-
#
|
|
16
|
-
# %w(TestA TestB).each do |klass|
|
|
17
|
-
# at.extra_class_map[klass] = "test/test_misc.rb"
|
|
18
|
-
# end
|
|
19
|
-
# end
|
|
20
|
-
|
|
21
|
-
# Autotest.add_hook :run_command do |at|
|
|
22
|
-
# system "rake build"
|
|
23
|
-
# end
|
data/Manifest.txt
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
.autotest
|
|
2
|
-
History.txt
|
|
3
|
-
Manifest.txt
|
|
4
|
-
README.md
|
|
5
|
-
Rakefile
|
|
6
|
-
lib/benchmark/compare.rb
|
|
7
|
-
lib/benchmark/ips.rb
|
|
8
|
-
lib/benchmark/ips/job.rb
|
|
9
|
-
lib/benchmark/ips/job/entry.rb
|
|
10
|
-
lib/benchmark/ips/job/stdout_report.rb
|
|
11
|
-
lib/benchmark/ips/report.rb
|
|
12
|
-
lib/benchmark/ips/share.rb
|
|
13
|
-
lib/benchmark/ips/stats/bootstrap.rb
|
|
14
|
-
lib/benchmark/ips/stats/sd.rb
|
|
15
|
-
lib/benchmark/ips/stats/stats_metric.rb
|
|
16
|
-
lib/benchmark/timing.rb
|
|
17
|
-
test/test_benchmark_ips.rb
|
data/Rakefile
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# -*- ruby -*-
|
|
2
|
-
|
|
3
|
-
require 'rubygems'
|
|
4
|
-
require 'hoe'
|
|
5
|
-
|
|
6
|
-
Hoe.plugin :minitest
|
|
7
|
-
Hoe.plugin :git
|
|
8
|
-
Hoe.plugin :ignore
|
|
9
|
-
|
|
10
|
-
hoe = Hoe.spec 'benchmark-ips' do
|
|
11
|
-
developer('Evan Phoenix', 'evan@phx.io')
|
|
12
|
-
|
|
13
|
-
self.readme_file = 'README.md'
|
|
14
|
-
|
|
15
|
-
license "MIT"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
file "#{hoe.spec.name}.gemspec" => ['Rakefile', "lib/benchmark/ips.rb"] do |t|
|
|
19
|
-
puts "Generating #{t.name}"
|
|
20
|
-
File.open(t.name, 'wb') { |f| f.write hoe.spec.to_ruby }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
desc "Generate or update the standalone gemspec file for the project"
|
|
24
|
-
task :gemspec => ["#{hoe.spec.name}.gemspec"]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# vim: syntax=ruby
|
data/test/test_benchmark_ips.rb
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
require "minitest/autorun"
|
|
2
|
-
require "benchmark/ips"
|
|
3
|
-
require "stringio"
|
|
4
|
-
require "tmpdir"
|
|
5
|
-
|
|
6
|
-
class TestBenchmarkIPS < Minitest::Test
|
|
7
|
-
def setup
|
|
8
|
-
@old_stdout = $stdout
|
|
9
|
-
$stdout = StringIO.new
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def teardown
|
|
13
|
-
$stdout = @old_stdout
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_kwargs
|
|
17
|
-
Benchmark.ips(:time => 1, :warmup => 1, :quiet => false) do |x|
|
|
18
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
assert $stdout.string.size > 0
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_warmup0
|
|
25
|
-
$stdout = @old_stdout
|
|
26
|
-
|
|
27
|
-
out, err = capture_io do
|
|
28
|
-
Benchmark.ips(:time => 1, :warmup => 0, :quiet => false) do |x|
|
|
29
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
refute_match(/Warming up -+/, out)
|
|
34
|
-
assert_empty err
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_output
|
|
38
|
-
Benchmark.ips(1) do |x|
|
|
39
|
-
x.report("operation") { 100 * 100 }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
assert $stdout.string.size > 0
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_quiet
|
|
46
|
-
Benchmark.ips(1, nil, true) do |x|
|
|
47
|
-
x.report("operation") { 100 * 100 }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
assert $stdout.string.size.zero?
|
|
51
|
-
|
|
52
|
-
Benchmark.ips(:quiet => true) do |x|
|
|
53
|
-
x.report("operation") { 100 * 100 }
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
assert $stdout.string.size.zero?
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_ips
|
|
60
|
-
report = Benchmark.ips do |x|
|
|
61
|
-
x.config(:time => 1, :warmup => 1)
|
|
62
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
63
|
-
x.report("sleep 0.05") { sleep(0.05) }
|
|
64
|
-
x.compare!
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
rep1 = report.entries[0]
|
|
68
|
-
rep2 = report.entries[1]
|
|
69
|
-
|
|
70
|
-
assert_equal "sleep 0.25", rep1.label
|
|
71
|
-
assert_equal 4, rep1.iterations
|
|
72
|
-
assert_in_delta 4.0, rep1.ips, 0.2
|
|
73
|
-
|
|
74
|
-
assert_equal "sleep 0.05", rep2.label
|
|
75
|
-
assert_in_delta 20.0, rep2.iterations.to_f, 1.0
|
|
76
|
-
assert_in_delta 20.0, rep2.ips, 2.0
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def test_ips_alternate_config
|
|
80
|
-
report = Benchmark.ips do |x|
|
|
81
|
-
x.time = 1
|
|
82
|
-
x.warmup = 1
|
|
83
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
rep = report.entries.first
|
|
87
|
-
|
|
88
|
-
assert_equal "sleep 0.25", rep.label
|
|
89
|
-
assert_equal 4, rep.iterations
|
|
90
|
-
assert_in_delta 4.0, rep.ips, 0.4
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def test_ips_old_config
|
|
94
|
-
report = Benchmark.ips(1,1) do |x|
|
|
95
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
rep = report.entries.first
|
|
99
|
-
|
|
100
|
-
assert_equal "sleep 0.25", rep.label
|
|
101
|
-
assert_equal 4, rep.iterations
|
|
102
|
-
assert_in_delta 4.0, rep.ips, 0.2
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def test_ips_config_suite
|
|
106
|
-
suite = Struct.new(:calls) do
|
|
107
|
-
def method_missing(method, *args)
|
|
108
|
-
calls << method
|
|
109
|
-
end
|
|
110
|
-
end.new([])
|
|
111
|
-
|
|
112
|
-
Benchmark.ips(0.1, 0.1) do |x|
|
|
113
|
-
x.config(:suite => suite)
|
|
114
|
-
x.report("job") {}
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
assert_equal [:warming, :warmup_stats, :running, :add_report], suite.calls
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def test_ips_defaults
|
|
121
|
-
report = Benchmark.ips do |x|
|
|
122
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
rep = report.entries.first
|
|
126
|
-
|
|
127
|
-
assert_equal "sleep 0.25", rep.label
|
|
128
|
-
assert_equal 4*5, rep.iterations
|
|
129
|
-
assert_in_delta 4.0, rep.ips, 0.2
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def test_ips_report_using_symbol
|
|
133
|
-
report = Benchmark.ips do |x|
|
|
134
|
-
x.report(:sleep_a_quarter_second) { sleep(0.25) }
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
rep = report.entries.first
|
|
138
|
-
|
|
139
|
-
assert_equal :sleep_a_quarter_second, rep.label
|
|
140
|
-
assert_equal 4*5, rep.iterations
|
|
141
|
-
assert_in_delta 4.0, rep.ips, 0.2
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def test_ips_default_data
|
|
145
|
-
report = Benchmark.ips do |x|
|
|
146
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
all_data = report.data
|
|
150
|
-
|
|
151
|
-
assert all_data
|
|
152
|
-
assert_equal "sleep 0.25", all_data[0][:name]
|
|
153
|
-
assert all_data[0][:ips]
|
|
154
|
-
assert all_data[0][:stddev]
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def test_ips_empty
|
|
158
|
-
report = Benchmark.ips do |_x|
|
|
159
|
-
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
all_data = report.data
|
|
163
|
-
|
|
164
|
-
assert all_data
|
|
165
|
-
assert_equal [], all_data
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def test_json_output
|
|
169
|
-
json_file = Tempfile.new("data.json")
|
|
170
|
-
|
|
171
|
-
Benchmark.ips do |x|
|
|
172
|
-
x.report("sleep 0.25") { sleep(0.25) }
|
|
173
|
-
x.json! json_file.path
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
json_data = json_file.read
|
|
177
|
-
assert json_data
|
|
178
|
-
|
|
179
|
-
data = JSON.parse json_data
|
|
180
|
-
assert data
|
|
181
|
-
assert_equal 1, data.size
|
|
182
|
-
assert_equal "sleep 0.25", data[0]["name"]
|
|
183
|
-
assert data[0]["ips"]
|
|
184
|
-
assert data[0]["stddev"]
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def test_hold!
|
|
188
|
-
temp_file_name = Dir::Tmpname.create(["benchmark-ips", ".tmp"]) { }
|
|
189
|
-
|
|
190
|
-
Benchmark.ips(:time => 0.001, :warmup => 0.001) do |x|
|
|
191
|
-
x.report("operation") { 100 * 100 }
|
|
192
|
-
x.report("operation2") { 100 * 100 }
|
|
193
|
-
x.hold! temp_file_name
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
assert File.exist?(temp_file_name)
|
|
197
|
-
File.unlink(temp_file_name)
|
|
198
|
-
end
|
|
199
|
-
end
|