Project

easy_bench

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A quick and easy benchmarking library for Ruby. Useful for benchmarking only part of an iteration, and accumulating the data to report later in the code.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Easy Bench

A quick and easy benchmarking library for Ruby. Useful for benchmarking only part of an iteration, and accumulating the data to report later in the code.

Features:

  • Measure the call times of only some of the expressions in your interation -- the timer is explicitly started and stopped for the duration of a block.
  • The result of the operation inside then benchmarked block is returned from the benchmarking call, so an EasyBench call can be wrapped around existing code with no changes.
  • This style allows for interleaving of two or more alternatives being benchmarked within an interaction, which can correct for ramp-up effects you might see if you benchmarked the alternatives sequentially.
  • Simple report output shows minimum, maximum, and mean call times.
  • The report output can also include a simple bar chart to visually inspect the data for outliners (only really useful for small runs of 20 iterations or so)

Install

$ sudo gem install easy_bench

Will also install the Sometimes Memoize gem.

Summary

A simple benchmark:

eb = EasyBench.new('Sleeping')

1.upto(10).each do |i|

  eb.caller{sleep(i.to_f / 10)}

end

eb.stats #=> {:count=>10, :total=>5.501514, :min=>0.100154, :max=>1.000172, :mean=>0.5501514000000001}

eb.report(true) # prints a report and simple bar chart as below

Sample report:

Sleeping

num runs       : 10
total run time : 5.501514s
min run time   : 0.100154s
max run time   : 1.000172s
ave run time   : 0.5501514000000001s

                  *
              * * *
          * * * * *
      * * * * * * *
* * * * * * * * * *

Interleaving:

eb1 = EasyBench.new('Old Way')
eb2 = EasyBench.new('New Way')

10000.times do

  eb1.caller{ SlowDB.call }
  eb2.caller{ HopefullyFasterDB.call }

end

eb1.report
eb2.report