Created
March 21, 2015 21:57
-
-
Save ms-ati/d399abe505a5999ebabd to your computer and use it in GitHub Desktop.
Benchmark rubygems list implementations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A benchmarking script for Rubygems' linked list implementation. | |
# See https://github.com/rubygems/rubygems/pull/1200 | |
# | |
# To run, clone the rubygems repo and place this file in the | |
# root of the checkout. Then run: | |
# | |
# ruby ./benchmark_rubygems_list.rb | |
# | |
require 'benchmark' | |
require './lib/rubygems/util/list.rb' | |
git_branch_name = `git rev-parse --abbrev-ref HEAD`.chomp | |
puts "\n#{'=' * 50}\nBenchmarking Gem::List in git branch #{git_branch_name}\n#{'=' * 50}\n\n" | |
NUM_LISTS = 1000 | |
LIST_SIZE = 1000 | |
NUM_TIMES = 100 | |
lists = Array.new(NUM_LISTS) { (0...LIST_SIZE).inject(nil) { |l, v| Gem::List.prepend(l, v) } } | |
Benchmark.bmbm do |x| | |
x.report("#{git_branch_name} to_a:") { NUM_TIMES.times { lists.map { |l| l.to_a } } } | |
x.report("#{git_branch_name} find:") { NUM_TIMES.times { lists.map { |l| l.find { |v| v < 0 } } } } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git co master | |
$ ruby ./benchmark_rubygems_list.rb | |
================================================== | |
Benchmarking Gem::List in git branch master | |
================================================== | |
Rehearsal ------------------------------------------------ | |
master to_a: 12.060000 0.170000 12.230000 ( 12.245445) | |
master find: 12.110000 0.010000 12.120000 ( 12.127869) | |
-------------------------------------- total: 24.350000sec | |
user system total real | |
master to_a: 11.090000 0.130000 11.220000 ( 11.227482) | |
master find: 11.720000 0.010000 11.730000 ( 11.736898) | |
$ git co more-dry-list | |
Switched to branch 'more-dry-list' | |
Your branch is up-to-date with 'origin/more-dry-list'. | |
msiegel@nantucket:~/Documents/workspace/OpenSource/rubygems$ ruby ./benchmark_rubygems_list.rb | |
================================================== | |
Benchmarking Gem::List in git branch more-dry-list | |
================================================== | |
Rehearsal ------------------------------------------------------- | |
more-dry-list to_a: 8.350000 0.280000 8.630000 ( 8.639509) | |
more-dry-list find: 11.330000 0.030000 11.360000 ( 11.363005) | |
--------------------------------------------- total: 19.990000sec | |
user system total real | |
more-dry-list to_a: 8.030000 0.240000 8.270000 ( 8.273676) | |
more-dry-list find: 11.710000 0.020000 11.730000 ( 11.726015) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment