Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

It's... CompareTime!

Compare execution times between Ruby blocks. Add a block to a class state using compare or with and compare them all later using print_results (in CLI) or sort_results if you want to use the results for something.

gem install compare_time

Let's compare something pretty obvious:

require 'compare_time'
require 'openssl'

please = # both params are optional
  5,                      # number of repetitions. default: 1
  silence_output: false   # whether to silence the output, doesn't matter here. default: true
  )"4096 bit") do 4096
end.with("2048") do 2048
end.with("1024 bit") do 1024

# will print:
# 1024 bit: 0.0156294590
# 2048 bit: 0.2788835170
# 4096 bit: 0.3576796250

Bang, bang, pow, pow! Tadaaam!

How does it work?

First of all, install and include the gem to your project. Either incliude it in your Gemfile and run bundle or just run:

gem install compare_time

Then, require the gem in your project file:

require 'compare_time'

To compare anything you want, you need to initialize a class. You can pass number of executions and whenever you want output to be silenced. You don't have to pass anything though to execute it only once with hidden noise.

comparator =

You can start by executing any block you want using either compare or with methods (with is an alias). It returns self so you can chain them if you want and/or use it later. Pass a desired name and a block to a compare method.'calculating 2**128') { 2**128 }

From there, you can compare anything with it as long as you need to.'calculating 2**256') { 2**256 }

Above two methods can be chained like this:'calculating 2**128') { 2**128 }
.with('calculating 2**256') { 2**256 }
.with('calculating 2**512') { 2**512 }

Then, when you are finished you just call print_results to display it to the console (when debugging) or sort_results when you need to pass it further.


So, summing everything up:

require 'compare_time'
comparator ='calculating 2**128') { 2**128 }
.with('calculating 2**256') { 2**256 }
.with('calculating 2**512') { 2**512 }'calculating 2**1024') { 2**1024 }
.with('calculating 2**2048') { 2**2048 }

comparator.print_results # => everything will be sorted by execution time and printed to STDOUT


Compare execution times for given blocks in Ruby



No releases published


No packages published


You can’t perform that action at this time.