Skip to content

Commit

Permalink
chore(benchmark): dry up benchmark codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytonyjan committed Oct 3, 2017
1 parent 7d590dc commit 5ebd36d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
13 changes: 13 additions & 0 deletions benchmark/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
require 'bundler'
Bundler.setup(:benchmark)

SAMPLES = {
ascii: [
%w[al al], %w[martha marhta], %w[jones johnson], %w[abcvwxyz cabvwxyz],
%w[dwayne duane], %w[dixon dicksonx], %w[fvie ten]
].freeze,
utf8: [
%w[馬英九 馬英丸], %w[蔡英文 蔡中文], %w[簡煒航 簡偉航], %w[焦玟綾 焦紋綾],
%w[眼球中央電視台 眼球中英電視台], %w[床前明月光 床前日月光],
%w[海水退了就知道誰沒穿褲子 海水退了就知道誰沒穿襪子],
%w[阿里山的姑娘美如水 阿里山的姑娘沒乳水]
].freeze
}.freeze

def gem_name_with_version(gem)
"#{gem} (#{Gem.loaded_specs[gem].version})"
end
13 changes: 4 additions & 9 deletions benchmark/native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@
require 'hotwater'
require 'amatch'

ary = [
%w[al al], %w[martha marhta], %w[jones johnson], %w[abcvwxyz cabvwxyz],
%w[dwayne duane], %w[dixon dicksonx], %w[fvie ten]
]

n = 100_000

Benchmark.bmbm do |x|
x.report "jaro_winkler (#{`git rev-parse --short HEAD`.chop!})" do
n.times { ary.each { |str1, str2| JaroWinkler.distance(str1, str2) } }
n.times { SAMPLES[:ascii].each { |str1, str2| JaroWinkler.distance(str1, str2) } }
end

x.report gem_name_with_version('fuzzy-string-match') do
jarow = FuzzyStringMatch::JaroWinkler.create(:native)
n.times { ary.each { |str1, str2| jarow.getDistance(str1, str2) } }
n.times { SAMPLES[:ascii].each { |str1, str2| jarow.getDistance(str1, str2) } }
end

x.report gem_name_with_version('hotwater') do
n.times { ary.each { |str1, str2| Hotwater.jaro_winkler_distance(str1, str2) } }
n.times { SAMPLES[:ascii].each { |str1, str2| Hotwater.jaro_winkler_distance(str1, str2) } }
end

x.report gem_name_with_version('amatch') do
n.times { ary.each { |str1, str2| Amatch::Jaro.new(str1).match(str2) } }
n.times { SAMPLES[:ascii].each { |str1, str2| Amatch::Jaro.new(str1).match(str2) } }
end
end
9 changes: 2 additions & 7 deletions benchmark/pure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
require 'jaro_winkler/jaro_winkler_pure'
require 'fuzzystringmatch'

ary = [
%w[al al], %w[martha marhta], %w[jones johnson], %w[abcvwxyz cabvwxyz],
%w[dwayne duane], %w[dixon dicksonx], %w[fvie ten]
]

n = 10_000

Benchmark.bmbm do |x|
x.report "jaro_winkler (#{`git rev-parse --short HEAD`.chop!})" do
n.times { ary.each { |str1, str2| JaroWinkler.distance(str1, str2) } }
n.times { SAMPLES[:ascii].each { |str1, str2| JaroWinkler.distance(str1, str2) } }
end

x.report gem_name_with_version('fuzzy-string-match') do
jarow = FuzzyStringMatch::JaroWinkler.create(:pure)
n.times { ary.each { |str1, str2| jarow.getDistance(str1, str2) } }
n.times { SAMPLES[:ascii].each { |str1, str2| jarow.getDistance(str1, str2) } }
end
end

0 comments on commit 5ebd36d

Please sign in to comment.