-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add a rake task to measure performance of each version
- Loading branch information
1 parent
5ebd36d
commit 6368e2d
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
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
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 |