百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

benchmark-driver

> 编程语言
开源

针对 Ruby 的功能完备的基准驱动

158 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

针对 Ruby 的功能完备的基准驱动

BenchmarkDriver

Fully-featured accurate benchmark driver for Ruby

Features

Accurate Measurement

  • Low overhead benchmark by running generated script instead of calling Proc
  • Profiling memory and high-precision real time
  • Running multiple times to minimize measurement errors

Pluggable & Fully Featured

  • Flexible and real-time output format in comparison, markdown table, graph, etc.
  • Measuring various metrics by specifying runners
  • Integrated benchmark support using external libraries
  • Runner and output format are all pluggable

Flexible Interface

  • Ruby interface similar to stdlib benchmark.rb, benchmark-ips
  • YAML input to easily manage structured benchmark set
  • Comparing multiple Ruby binaries, even with miniruby

Installation

$ gem install benchmark_driver

Usage

Ruby Interface

This interface generates code to profile with low overhead and executes it.

rb
require 'benchmark_driver'

Benchmark.driver do |x|
  x.prelude ])
benchmark: erb.result

you 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  slower

Running multiple scripts

One YAML file can contain multiple benchmark scripts. With following example_multi.yml,

yaml
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.

…

Output Options

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:

rb
Benchmark.driver do |x|
  x.prelude %{ array = [] }
  x.report 'Array#empty?', %{ array.empty? }
  x.output 'markdown'
end

With following blank_loop.yml,

yaml
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:

compare

…

simple

$ 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

markdown

$ 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

record

Measure first, output with various formats later.

…

gruff

There is benchmark_driver-output-gruff plugin that renders a graph using gruff.gem.

benchmark-driver.github.io

Benchmark results for https://benchmark-driver.github.io are also stored by output plugin. You can integrate any system as you like.

Runner Options

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

ips

…

time

$ 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

memory

$ 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  larger

once

Only for testing purpose.

…

ruby_stdout

See following example:

  • https://github.com/benchmark-driver/optcarrot

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  slower

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/benchmark-driver/benchmark-driver.

License

The gem is available as open source under the terms of the MIT License.

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubybenchmarkruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言