针对 Ruby 的功能完备的基准驱动
Fully-featured accurate benchmark driver for Ruby
$ gem install benchmark_driverThis interface generates code to profile with low overhead and executes it.
require 'benchmark_driver'
Benchmark.driver do |x|
x.prelude ])
benchmark: erb.resultyou can benchmark the script with multiple ruby executables.
$ benchmark-driver example_single.yml --rbenv '2.4.1;2.5.0'
Warming up --------------------------------------
erb.result 71.683k i/s
Calculating -------------------------------------
2.4.1 2.5.0
erb.result 72.387k 75.046k i/s - 215.049k times in 2.970833s 2.865581s
Comparison:
erb.result
2.5.0: 75045.5 i/s
2.4.1: 72386.8 i/s - 1.04x slowerOne YAML file can contain multiple benchmark scripts.
With following example_multi.yml,
prelude: |
a = 'a' * 100
b = 'b' * 100
benchmark:
join: '[a, b].join'
str-interp: '"#{a}#{b}"'you can benchmark the scripts with multiple ruby executables.
…By default, there are following output options.
| Output | Description |
|---|---|
| compare | benchmark-ips's compare!-like output (default) |
| simple | ruby's original benchmark/driver.rb-like simple output |
| markdown | output in markdown table |
| record | serialize results in benchmark_driver.record.yml, to change outputs later as you like |
With benchmark-driver CLI, you can specify it with -o [output] or --output [output].
With Ruby interface, you can specify it like:
Benchmark.driver do |x|
x.prelude %{ array = [] }
x.report 'Array#empty?', %{ array.empty? }
x.output 'markdown'
endWith following blank_loop.yml,
loop_count: 20000000
prelude: |
class Array
alias_method :blank?, :empty?
end
array = []
benchmark:
empty: array.empty?
blank: array.blank?you can output results in various ways like:
…$ benchmark-driver blank_loop.yml --output simple --rbenv '2.4.2;2.5.0'
benchmark results (i/s):
2.4.2 2.5.0
empty 184.084M 117.319M
blank 65.843M 62.093M$ benchmark-driver blank_loop.yml --output markdown --rbenv '2.4.2;2.5.0'benchmark results (i/s)
| 2.4.2 | 2.5.0 | |
|---|---|---|
| empty | 187.296M | 117.662M |
| blank | 58.895M | 58.852M |
Measure first, output with various formats later.
…There is benchmark_driver-output-gruff plugin that renders a graph using gruff.gem.
Benchmark results for https://benchmark-driver.github.io are also stored by output plugin. You can integrate any system as you like.
Runner decides metrics to be collected. There are following default runner options.
ips, time, memory, once
| Runner | Description |
|---|---|
| ips | Iteration per second (default) |
| time | Elapsed seconds |
| memory | Max resident set. This is supported only on Linux and macOS for now. |
| once | Forces loop_count to 1 for testing |
| ruby_stdout | Special runner to integrate existing benchmarks |
…$ benchmark-driver blank_loop.yml --runner time --rbenv '2.4.3;2.5.0'
Calculating -------------------------------------
2.4.3 2.5.0
empty 0.087 0.110 s - 20.000M times
blank 0.217 0.219 s - 20.000M times
Comparison:
empty
2.5.0: 0.1 s
2.4.3: 0.1 s - 1.26x slower
blank
2.5.0: 0.2 s
2.4.3: 0.2 s - 1.01x slower$ benchmark-driver blank_loop.yml --runner memory --rbenv '2.4.3;2.5.0'
Calculating -------------------------------------
2.4.3 2.5.0
empty 9.192M 9.364M bytes - 20.000M times
blank 9.080M 9.372M bytes - 20.000M times
Comparison:
empty
2.4.3: 9192000.0 bytes
2.5.0: 9364000.0 bytes - 1.02x larger
blank
2.4.3: 9080000.0 bytes
2.5.0: 9372000.0 bytes - 1.03x largerOnly for testing purpose.
…See following example:
If your benchmark can run with ruby foo bar, specify foo bar to command:.
Then write stdout_to_metrics: to convert stdout to metrics. This runner can be used only with YAML interface for now.
$ benchmark-driver benchmark.yml --verbose 1 --rbenv '2.6.0-dev;2.6.0-dev --jit'
2.6.0-dev: ruby 2.6.0dev (2018-03-21 trunk 62870) [x86_64-linux]
2.6.0-dev --jit: ruby 2.6.0dev (2018-03-21 trunk 62870) +JIT [x86_64-linux]
Calculating -------------------------------------
2.6.0-dev 2.6.0-dev --jit
optcarrot 51.866 67.445 fps
Comparison:
optcarrot
2.6.0-dev --jit: 67.4 fps
2.6.0-dev: 51.9 fps - 1.30x slowerBug reports and pull requests are welcome on GitHub at https://github.com/benchmark-driver/benchmark-driver.
The gem is available as open source under the terms of the MIT License.
暂无开放 Issues,或尚未同步最近议题。