benchmark-ips 2.10.0 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0516f3e1e35f43a8fe32a6f32357aa124478ba54228ffe57d928cfc1231851bc
4
- data.tar.gz: d62da6a6c1d2696b7667bd125ffe6bb2c33b3d61da5c393e729d7ca8a3d70ee7
3
+ metadata.gz: 194a6da5977a23dc733ade6dadaefe1a7d7215678d6135ff33d5c37304bec993
4
+ data.tar.gz: e072ffd46009a79e13990e7435e1415ec24fd0407f86d566208fc597b8e33f7d
5
5
  SHA512:
6
- metadata.gz: b644d293980f1ac9e3158abbe4f2c9d44d23185878edb9cb3861f3ca4f6837d557f89f8eb19bfcc42a45f53f3d112f2fe3ab22fc85a9633ede7e678b5fb90336
7
- data.tar.gz: afe9972cdecdb2f42d4946afbac3d02cb3ead3a3d47a804960026ea77487cf885f6ddd7368edb13c522ee11e251599bf953d3d9a8172411c10e7259f7e9352b2
6
+ metadata.gz: 5b3a8e41f223d3945daf11329e7cd68b1cc41f9b08b9f3f2e9e5a471a37134782f4e1f78caca102b7b3b08eb179ac4d78868bb1f97bfab4ac1ccef22aa38d42d
7
+ data.tar.gz: e5cd27c03050929b8edf402264c0f5a32560550ee6d79456d2513ae9b4a76f763f669a32ba4cc3bf7a45e7c086426631c2ba26724a749192fc637046bfd6a495
data/History.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 2.11.0 / 2023-02-15
2
+
3
+ * Feature
4
+ * Adds .json! method to the ips block argument, allowing you to print the output as JSON to a file or STDOUT.
5
+
1
6
  ### 2.10.0 / 2022-02-17
2
7
 
3
8
  * Feature
data/README.md CHANGED
@@ -237,6 +237,29 @@ Benchmark.ips do |x|
237
237
  end
238
238
  ```
239
239
 
240
+ ### Output as JSON
241
+
242
+ You can generate output in JSON. If you want to write JSON to a file, pass filename to `json!` method:
243
+
244
+ ```ruby
245
+ Benchmark.ips do |x|
246
+ x.report("some report") { }
247
+ x.json! 'filename.json'
248
+ end
249
+ ```
250
+
251
+ If you want to write JSON to STDOUT, pass `STDOUT` to `json!` method and set `quiet = true` before `json!`:
252
+
253
+ ```ruby
254
+ Benchmark.ips do |x|
255
+ x.report("some report") { }
256
+ x.quiet = true
257
+ x.json! STDOUT
258
+ end
259
+ ```
260
+
261
+ This is useful when the output from `benchmark-ips` becomes an input of other tools via stdin.
262
+
240
263
  ## REQUIREMENTS:
241
264
 
242
265
  * None!
@@ -183,9 +183,13 @@ module Benchmark
183
183
  # Generate json from Report#data to given path.
184
184
  # @param path [String] path to generate json.
185
185
  def generate_json(path)
186
- File.open path, "w" do |f|
187
- require "json"
188
- f.write JSON.pretty_generate(data)
186
+ require "json"
187
+ if path.respond_to?(:write) # STDOUT
188
+ path.write JSON.pretty_generate(data)
189
+ else
190
+ File.open path, "w" do |f|
191
+ f.write JSON.pretty_generate(data)
192
+ end
189
193
  end
190
194
  end
191
195
  end
@@ -24,9 +24,9 @@ module Benchmark
24
24
  # @returns [Array<Float, nil>] the slowdown and the error (not calculated for standard deviation)
25
25
  def slowdown(baseline)
26
26
  if baseline.central_tendency > central_tendency
27
- [baseline.central_tendency.to_f / central_tendency, 0]
27
+ [baseline.central_tendency.to_f / central_tendency, nil]
28
28
  else
29
- [central_tendency.to_f / baseline.central_tendency, 0]
29
+ [central_tendency.to_f / baseline.central_tendency, nil]
30
30
  end
31
31
  end
32
32
 
data/lib/benchmark/ips.rb CHANGED
@@ -18,10 +18,10 @@ module Benchmark
18
18
  module IPS
19
19
 
20
20
  # Benchmark-ips Gem version.
21
- VERSION = "2.10.0"
21
+ VERSION = "2.11.0"
22
22
 
23
23
  # CODENAME of current version.
24
- CODENAME = "Watashi Wa Genki"
24
+ CODENAME = "We Do This Once A Year"
25
25
 
26
26
  # Measure code in block, each code's benchmarked result will display in
27
27
  # iteration per second with standard deviation in given time.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark-ips
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.2.26
92
+ rubygems_version: 3.3.20
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: A iterations per second enhancement to Benchmark.