benchmark-ips 2.1.1 → 2.2.0
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 +24 -0
- data/README.md +44 -1
- data/Rakefile +1 -0
- data/lib/benchmark/ips.rb +7 -3
- data/lib/benchmark/ips/job.rb +21 -2
- data/lib/benchmark/ips/report.rb +28 -2
- data/test/test_benchmark_ips.rb +75 -0
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10d2721496232fa66554efc54374e96a44bb8b46
|
4
|
+
data.tar.gz: 0eaef49055af4e91846cf61ccd8eafb4c2c779cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a6eb4ecc46877f3b73836d2b1999b1ed895bc553a5a6baf2470ad3225343b44bc58574eaae6446f3ae658ec383ec7cf61059283df1d08d1cf1395ba64d9895f
|
7
|
+
data.tar.gz: ccf501ab18c3243bcafc36fc891d8d9cb1b083a317f9743ae6863cc0f956cde0c3f01cadd1ad73430a59a17d642acb6be0c25827ad12b398b0677f46b311e375
|
data/History.txt
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
=== 2.2.0 / 2015-05-09
|
2
|
+
|
3
|
+
* 1 minor features:
|
4
|
+
* Fix quiet mode
|
5
|
+
* Allow passing a custom suite via config
|
6
|
+
* Silent a job if a suite was passed and is quiet
|
7
|
+
* Export report to json file.
|
8
|
+
* Accept symbol as report's argument.
|
9
|
+
|
10
|
+
* 2 doc fixes:
|
11
|
+
* Squish duplicate `to` in README
|
12
|
+
* Update copyright to 2015. [ci skip]
|
13
|
+
|
14
|
+
* 9 PRs merged:
|
15
|
+
* Merge pull request #37 from splattael/patch-1
|
16
|
+
* Merge pull request #36 from kirs/quiet-mode
|
17
|
+
* Merge pull request #35 from JuanitoFatas/doc/suite
|
18
|
+
* Merge pull request #34 from splattael/config-suite
|
19
|
+
* Merge pull request #33 from splattael/suite-quiet
|
20
|
+
* Merge pull request #32 from O-I/remove-gemfile-lock
|
21
|
+
* Merge pull request #31 from JuanitoFatas/doc/bump-copyright-year
|
22
|
+
* Merge pull request #29 from JuanitoFatas/feature/json-export
|
23
|
+
* Merge pull request #26 from JuanitoFatas/feature/takes-symbol-as-report-parameter
|
24
|
+
|
1
25
|
=== 2.1.1 / 2015-01-12
|
2
26
|
|
3
27
|
* 1 minor fix:
|
data/README.md
CHANGED
@@ -93,6 +93,49 @@ One benefit to using this method is benchmark-ips automatically determines the
|
|
93
93
|
data points for testing our code, so we can focus on the results instead of
|
94
94
|
guessing iteration counts as we do with the traditional Benchmark library.
|
95
95
|
|
96
|
+
### Custom Suite
|
97
|
+
|
98
|
+
Pass a custom suite to disable garbage collection during benchmark:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
require 'benchmark/ips'
|
102
|
+
|
103
|
+
# Enable and start GC before each job run. Disable GC afterwards.
|
104
|
+
#
|
105
|
+
# Inspired by https://www.omniref.com/ruby/2.2.1/symbols/Benchmark/bm?#annotation=4095926&line=182
|
106
|
+
class GCSuite
|
107
|
+
def warming(*)
|
108
|
+
run_gc
|
109
|
+
end
|
110
|
+
|
111
|
+
def running(*)
|
112
|
+
run_gc
|
113
|
+
end
|
114
|
+
|
115
|
+
def warmup_stats(*)
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_report(*)
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def run_gc
|
124
|
+
GC.enable
|
125
|
+
GC.start
|
126
|
+
GC.disable
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
suite = GCSuite.new
|
131
|
+
|
132
|
+
Benchmark.ips do |x|
|
133
|
+
x.config(:suite => suite)
|
134
|
+
x.report("job1") { ... }
|
135
|
+
x.report("job2") { ... }
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
96
139
|
## REQUIREMENTS:
|
97
140
|
|
98
141
|
* None!
|
@@ -114,7 +157,7 @@ and generate the RDoc.
|
|
114
157
|
|
115
158
|
(The MIT License)
|
116
159
|
|
117
|
-
Copyright (c)
|
160
|
+
Copyright (c) 2015 Evan Phoenix
|
118
161
|
|
119
162
|
Permission is hereby granted, free of charge, to any person obtaining
|
120
163
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
data/lib/benchmark/ips.rb
CHANGED
@@ -11,7 +11,7 @@ module Benchmark
|
|
11
11
|
module IPS
|
12
12
|
|
13
13
|
# Benchmark-ips Gem version.
|
14
|
-
VERSION = "2.
|
14
|
+
VERSION = "2.2.0"
|
15
15
|
|
16
16
|
# CODENAME of current version.
|
17
17
|
CODENAME = "Springtime Hummingbird Dance"
|
@@ -21,7 +21,7 @@ module Benchmark
|
|
21
21
|
# @param time [Integer] Specify how long should benchmark your code in seconds.
|
22
22
|
# @param warmup [Integer] Specify how long should Warmup time run in seconds.
|
23
23
|
# @return [Report]
|
24
|
-
def ips(time=nil, warmup=nil)
|
24
|
+
def ips(time=nil, warmup=nil, quiet=false)
|
25
25
|
suite = nil
|
26
26
|
|
27
27
|
sync, $stdout.sync = $stdout.sync, true
|
@@ -30,7 +30,7 @@ module Benchmark
|
|
30
30
|
suite = Benchmark::Suite.current
|
31
31
|
end
|
32
32
|
|
33
|
-
quiet
|
33
|
+
quiet ||= (suite && suite.quiet?)
|
34
34
|
|
35
35
|
job = Job.new({:suite => suite,
|
36
36
|
:quiet => quiet
|
@@ -58,6 +58,10 @@ module Benchmark
|
|
58
58
|
job.run_comparison
|
59
59
|
end
|
60
60
|
|
61
|
+
if job.json?
|
62
|
+
job.generate_json
|
63
|
+
end
|
64
|
+
|
61
65
|
return job.full_report
|
62
66
|
end
|
63
67
|
|
data/lib/benchmark/ips/job.rb
CHANGED
@@ -13,11 +13,11 @@ module Benchmark
|
|
13
13
|
# Entries in Benchmark Jobs.
|
14
14
|
class Entry
|
15
15
|
# Instantiate the Benchmark::IPS::Job::Entry.
|
16
|
-
# @param label [
|
16
|
+
# @param label [#to_s] Label of Benchmarked code.
|
17
17
|
# @param action [String, Proc] Code to be benchmarked.
|
18
18
|
# @raise [ArgumentError] Raises when action is not String or not responding to +call+.
|
19
19
|
def initialize(label, action)
|
20
|
-
@label = label
|
20
|
+
@label = label.to_s
|
21
21
|
|
22
22
|
if action.kind_of? String
|
23
23
|
compile action
|
@@ -126,6 +126,7 @@ module Benchmark
|
|
126
126
|
@quiet = opts[:quiet] || false
|
127
127
|
@list = []
|
128
128
|
@compare = false
|
129
|
+
@json_path = false
|
129
130
|
|
130
131
|
@timing = {}
|
131
132
|
@full_report = Report.new
|
@@ -141,6 +142,7 @@ module Benchmark
|
|
141
142
|
def config opts
|
142
143
|
@warmup = opts[:warmup] if opts[:warmup]
|
143
144
|
@time = opts[:time] if opts[:time]
|
145
|
+
@suite = opts[:suite] if opts[:suite]
|
144
146
|
end
|
145
147
|
|
146
148
|
# Return true if job needs to be compared.
|
@@ -154,6 +156,18 @@ module Benchmark
|
|
154
156
|
@compare = true
|
155
157
|
end
|
156
158
|
|
159
|
+
|
160
|
+
# Return true if job needs to generate json.
|
161
|
+
# @return [Boolean] Need to generate json?
|
162
|
+
def json?
|
163
|
+
!!@json_path
|
164
|
+
end
|
165
|
+
|
166
|
+
# Set @json_path to given path, defaults to "data.json".
|
167
|
+
def json!(path="data.json")
|
168
|
+
@json_path = path
|
169
|
+
end
|
170
|
+
|
157
171
|
# Registers the given label and block pair in the job list.
|
158
172
|
# @param label [String] Label of benchmarked code.
|
159
173
|
# @param str [String] Code to be benchamrked.
|
@@ -302,6 +316,11 @@ module Benchmark
|
|
302
316
|
@full_report.run_comparison
|
303
317
|
end
|
304
318
|
|
319
|
+
# Generate json from +@full_report+.
|
320
|
+
def generate_json
|
321
|
+
@full_report.generate_json @json_path
|
322
|
+
end
|
323
|
+
|
305
324
|
# Create report by add entry to +@full_report+.
|
306
325
|
# @param item [Benchmark::IPS::Job::Entry] Report item.
|
307
326
|
# @param measured_us [Integer] Measured time in microsecond.
|
data/lib/benchmark/ips/report.rb
CHANGED
@@ -10,14 +10,14 @@ module Benchmark
|
|
10
10
|
# Represents benchmarking code data for Report.
|
11
11
|
class Entry
|
12
12
|
# Instantiate the Benchmark::IPS::Report::Entry.
|
13
|
-
# @param [
|
13
|
+
# @param [#to_s] label Label of entry.
|
14
14
|
# @param [Integer] us Measured time in microsecond.
|
15
15
|
# @param [Integer] iters Iterations.
|
16
16
|
# @param [Float] ips Iterations per second.
|
17
17
|
# @param [Float] ips_sd Standard deviation of iterations per second.
|
18
18
|
# @param [Integer] cycles Number of Cycles.
|
19
19
|
def initialize(label, us, iters, ips, ips_sd, cycles)
|
20
|
-
@label = label
|
20
|
+
@label = label.to_s
|
21
21
|
@microseconds = us
|
22
22
|
@iterations = iters
|
23
23
|
@ips = ips
|
@@ -124,6 +124,7 @@ module Benchmark
|
|
124
124
|
# Instantiate the Report.
|
125
125
|
def initialize
|
126
126
|
@entries = []
|
127
|
+
@data = nil
|
127
128
|
end
|
128
129
|
|
129
130
|
# Add entry to report.
|
@@ -139,10 +140,35 @@ module Benchmark
|
|
139
140
|
@entries.last
|
140
141
|
end
|
141
142
|
|
143
|
+
# Entries data in array for generate json.
|
144
|
+
# Each entry is a hash, consists of:
|
145
|
+
# name: Entry#label
|
146
|
+
# ips: Entry#ips
|
147
|
+
# stddev: Entry#ips_sd
|
148
|
+
# @return [Array] Array of entries
|
149
|
+
def data
|
150
|
+
@data ||= @entries.collect do |entry|
|
151
|
+
{
|
152
|
+
name: entry.label,
|
153
|
+
ips: entry.ips,
|
154
|
+
stddev: entry.ips_sd
|
155
|
+
}
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
142
159
|
# Run comparison of entries.
|
143
160
|
def run_comparison
|
144
161
|
Benchmark.compare(*@entries)
|
145
162
|
end
|
163
|
+
|
164
|
+
# Generate json from Report#data to given path.
|
165
|
+
# @param path [String] path to generate json.
|
166
|
+
def generate_json(path)
|
167
|
+
File.open path, "w" do |f|
|
168
|
+
require "json"
|
169
|
+
f.write JSON.pretty_generate(data)
|
170
|
+
end
|
171
|
+
end
|
146
172
|
end
|
147
173
|
end
|
148
174
|
end
|
data/test/test_benchmark_ips.rb
CHANGED
@@ -12,6 +12,22 @@ class TestBenchmarkIPS < Minitest::Test
|
|
12
12
|
$stdout = @old_stdout
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_output
|
16
|
+
Benchmark.ips(1) do |x|
|
17
|
+
x.report("operation") { 100 * 100 }
|
18
|
+
end
|
19
|
+
|
20
|
+
assert $stdout.string.size > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_quiet
|
24
|
+
Benchmark.ips(1, nil, true) do |x|
|
25
|
+
x.report("operation") { 100 * 100 }
|
26
|
+
end
|
27
|
+
|
28
|
+
assert $stdout.string.size.zero?
|
29
|
+
end
|
30
|
+
|
15
31
|
def test_ips
|
16
32
|
report = Benchmark.ips do |x|
|
17
33
|
x.config(:time => 1, :warmup => 1)
|
@@ -58,6 +74,21 @@ class TestBenchmarkIPS < Minitest::Test
|
|
58
74
|
assert_in_delta 4.0, rep.ips, 0.2
|
59
75
|
end
|
60
76
|
|
77
|
+
def test_ips_config_suite
|
78
|
+
suite = Struct.new(:calls) do
|
79
|
+
def method_missing(method, *args)
|
80
|
+
calls << method
|
81
|
+
end
|
82
|
+
end.new([])
|
83
|
+
|
84
|
+
Benchmark.ips(0.1, 0.1) do |x|
|
85
|
+
x.config(:suite => suite)
|
86
|
+
x.report("job") {}
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_equal [:warming, :warmup_stats, :running, :add_report], suite.calls
|
90
|
+
end
|
91
|
+
|
61
92
|
def test_ips_defaults
|
62
93
|
report = Benchmark.ips do |x|
|
63
94
|
x.report("sleep 0.25") { sleep(0.25) }
|
@@ -69,4 +100,48 @@ class TestBenchmarkIPS < Minitest::Test
|
|
69
100
|
assert_equal 4*5, rep.iterations
|
70
101
|
assert_in_delta 4.0, rep.ips, 0.2
|
71
102
|
end
|
103
|
+
|
104
|
+
def test_ips_report_using_symbol
|
105
|
+
report = Benchmark.ips do |x|
|
106
|
+
x.report(:sleep_a_quarter_second) { sleep(0.25) }
|
107
|
+
end
|
108
|
+
|
109
|
+
rep = report.entries.first
|
110
|
+
|
111
|
+
assert_equal "sleep_a_quarter_second", rep.label
|
112
|
+
assert_equal 4*5, rep.iterations
|
113
|
+
assert_in_delta 4.0, rep.ips, 0.2
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_ips_default_data
|
117
|
+
report = Benchmark.ips do |x|
|
118
|
+
x.report("sleep 0.25") { sleep(0.25) }
|
119
|
+
end
|
120
|
+
|
121
|
+
all_data = report.data
|
122
|
+
|
123
|
+
assert all_data
|
124
|
+
assert_equal "sleep 0.25", all_data[0][:name]
|
125
|
+
assert all_data[0][:ips]
|
126
|
+
assert all_data[0][:stddev]
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_json_output
|
130
|
+
json_file = Tempfile.new("data.json")
|
131
|
+
|
132
|
+
Benchmark.ips do |x|
|
133
|
+
x.report("sleep 0.25") { sleep(0.25) }
|
134
|
+
x.json! json_file.path
|
135
|
+
end
|
136
|
+
|
137
|
+
json_data = json_file.read
|
138
|
+
assert json_data
|
139
|
+
|
140
|
+
data = JSON.parse json_data
|
141
|
+
assert data
|
142
|
+
assert_equal 1, data.size
|
143
|
+
assert_equal "sleep 0.25", data[0]["name"]
|
144
|
+
assert data[0]["ips"]
|
145
|
+
assert data[0]["stddev"]
|
146
|
+
end
|
72
147
|
end
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Phoenix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
19
|
+
version: '5.5'
|
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.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,5 +100,4 @@ rubygems_version: 2.2.2
|
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: A iterations per second enhancement to Benchmark.
|
103
|
-
test_files:
|
104
|
-
- test/test_benchmark_ips.rb
|
103
|
+
test_files: []
|