Skip to content

Commit

Permalink
Add readygo benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Feb 4, 2015
1 parent b131aa2 commit 5d52e65
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "vendor/readygo"]
path = vendor/readygo
url = https://github.com/garybernhardt/readygo.git
1 change: 1 addition & 0 deletions .readygo
@@ -0,0 +1 @@
{"readygo_file_format_version":1,"benchmark_results":[["VersionSorter .sort",[1.62,1.715,1.6520000000000001,1.6560000000000001,1.7550000000000001,1.796,1.754,1.7340000000000002,1.847,1.775,1.8730000000000002,1.809,1.707,1.8110000000000002,1.804,1.8900000000000001]],["VersionSorter .rsort",[1.7520000000000002,1.7600000000000002,1.7240000000000002,1.71,2.0820000000000003,1.8,2.711,1.6460000000000001,1.765,1.736,1.895,1.728,1.543,1.825,1.592,1.659]]]}
5 changes: 5 additions & 0 deletions Rakefile
Expand Up @@ -18,3 +18,8 @@ end
desc "Compile the native extension"
task :compile => 'lib/version_sorter.bundle'
task :test => :compile

desc "Run the benchmark"
task :benchmark => :compile do
sh 'script/benchmark'
end
16 changes: 16 additions & 0 deletions bin/rake
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rake', 'rake')
4 changes: 4 additions & 0 deletions bin/readygo
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e

exec env ruby -Ilib vendor/readygo/readygo.rb "$@"
22 changes: 22 additions & 0 deletions script/benchmark
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Usage: script/benchmark [compare|record]
set -e

task="${1:-compare}"

case "$task" in
record )
bin/rake
bin/readygo --record test/benchmark.rb
;;
compare )
bin/readygo --compare test/benchmark.rb
;;
-h | --help )
sed -ne '/^#/!q;s/.\{1,2\}//;1d;p' < "$0"
exit 0
;;
* )
"$0" --help >&2
exit 1
esac
5 changes: 5 additions & 0 deletions script/bootstrap
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e

git submodule update --init
bundle install
15 changes: 15 additions & 0 deletions test/benchmark.rb
@@ -0,0 +1,15 @@
require 'version_sorter'

ready "VersionSorter" do
before do
@versions = File.readlines(File.expand_path('../tags.txt', __FILE__)).map(&:chomp)
end

go ".sort" do
VersionSorter.sort @versions
end

go ".rsort" do
VersionSorter.rsort @versions
end
end
9 changes: 0 additions & 9 deletions test/version_sorter_test.rb
Expand Up @@ -25,12 +25,3 @@ def test_reverse_sorts_verisons_correctly
assert_equal sorted_versions, rsort(versions)
end
end

require 'benchmark'
versions = IO.read(File.dirname(__FILE__) + '/tags.txt').split("\n")
count = 10
Benchmark.bm(20) do |x|
x.report("sort") { count.times { VersionSorter.sort(versions) } }
x.report("rsot") { count.times { VersionSorter.rsort(versions) } }
end
puts
1 change: 1 addition & 0 deletions vendor/readygo
Submodule readygo added at 9c9747
2 changes: 1 addition & 1 deletion version_sorter.gemspec
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.summary = "Fast sorting of version strings"
s.description = "VersionSorter is a C extension that does fast sorting of large sets of version strings."

s.files = Dir['{bin,lib,ext}/**/*', 'LICENSE*']
s.files = Dir['{lib,ext}/**/*', 'LICENSE*']
s.extensions << 'ext/version_sorter/extconf.rb'

# include only files in version control
Expand Down

0 comments on commit 5d52e65

Please sign in to comment.