Skip to content

Commit

Permalink
chore: add a rake task to measure performance of each version
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytonyjan committed Oct 3, 2017
1 parent 5ebd36d commit 6368e2d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ namespace :benchmark do
load File.expand_path("../benchmark/pure.rb", __FILE__)
puts
end

task :measure do
tags = ENV['TAGS'] ? ENV['TAGS'].split(',') : `git tag --list`.split.select { |v| v.match? /\Av1\.[1-9]\.\d\z/ }
puts 'version,label,utime,stime,cutime,cstime,real'
tags.each do |tag|
sh("git checkout -f #{tag} 1>&2")
sh('git checkout master -- benchmark 1>&2')
sh('bundle exec rake clobber compile 1>&2')
sh("ruby #{File.expand_path("../benchmark/measure.rb", __FILE__)}")
end
end
end

task compare: :compile do
Expand Down
39 changes: 39 additions & 0 deletions benchmark/measure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require File.expand_path('../env', __FILE__)
require 'jaro_winkler'
require 'benchmark'
require 'csv'

csv = CSV.new($stdout)
n = 100_000

jobs = case JaroWinkler::VERSION
when /\A1\.1/
{
ascii: -> { n.times { SAMPLES[:ascii].each { |str1, str2| JaroWinkler.c_distance(str1, str2) } } }
}
when /\A1\.[2-3]/
{
ascii: -> { n.times { SAMPLES[:ascii].each { |str1, str2| JaroWinkler.c_distance(str1, str2) } } },
utf8: -> { n.times { SAMPLES[:utf8].each { |str1, str2| JaroWinkler.c_distance(str1, str2) } } }
}
else
{
ascii: -> { n.times { SAMPLES[:ascii].each { |str1, str2| JaroWinkler.distance(str1, str2) } } },
utf8: -> { n.times { SAMPLES[:utf8].each { |str1, str2| JaroWinkler.distance(str1, str2) } } }
}
end

# rehearsal

jobs.each { |label, job| Benchmark.measure(label, &job) }

# take

jobs.each do |label, job|
GC.start
tms = Benchmark.measure(label, &job)
# version,label,utime,stime,cutime,cstime,real
csv << [JaroWinkler::VERSION, *tms.to_a]
end

0 comments on commit 6368e2d

Please sign in to comment.