Skip to content

Commit

Permalink
chore: refine benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytonyjan committed Oct 1, 2017
1 parent fba1b2e commit e6b93fb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
9 changes: 9 additions & 0 deletions benchmark/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

$LOAD_PATH << File.expand_path('../../lib', __FILE__)
require 'bundler'
Bundler.setup(:benchmark)

def gem_name_with_version(gem)
"#{gem} (#{Gem.loaded_specs[gem].version})"
end
31 changes: 19 additions & 12 deletions benchmark/native.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
# frozen_string_literal: true

require File.expand_path('../env', __FILE__)
require 'benchmark'
require 'jaro_winkler'
require 'jaro_winkler/version'
require 'jaro_winkler/jaro_winkler_ext'
require 'fuzzystringmatch'
require 'hotwater'
require 'amatch'
ary = [['al', 'al'], ['martha', 'marhta'], ['jones', 'johnson'], ['abcvwxyz', 'cabvwxyz'], ['dwayne', 'duane'], ['dixon', 'dicksonx'], ['fvie', 'ten']]

n = 100000
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 #{JaroWinkler::VERSION}" do
n.times{ ary.each{ |str1, str2| JaroWinkler.distance(str1, str2) } }
x.report "jaro_winkler (#{`git rev-parse --short HEAD`.chop!})" do
n.times { ary.each { |str1, str2| JaroWinkler.distance(str1, str2) } }
end

x.report "fuzzystringmatch #{Gem.loaded_specs['fuzzy-string-match'].version}" do
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 { ary.each { |str1, str2| jarow.getDistance(str1, str2) } }
end

x.report "hotwater #{Gem.loaded_specs['hotwater'].version}" do
n.times{ ary.each{ |str1, str2| Hotwater.jaro_winkler_distance(str1, str2) } }
x.report gem_name_with_version('hotwater') do
n.times { ary.each { |str1, str2| Hotwater.jaro_winkler_distance(str1, str2) } }
end

x.report "amatch #{Gem.loaded_specs['amatch'].version}" do
n.times{ ary.each{ |str1, str2| Amatch::Jaro.new(str1).match(str2) } }
x.report gem_name_with_version('amatch') do
n.times { ary.each { |str1, str2| Amatch::Jaro.new(str1).match(str2) } }
end
end
23 changes: 15 additions & 8 deletions benchmark/pure.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
require 'jaro_winkler/jaro_winkler_pure'
require 'jaro_winkler/version'
# frozen_string_literal: true

require File.expand_path('../env', __FILE__)
require 'benchmark'
require 'jaro_winkler/jaro_winkler_pure'
require 'fuzzystringmatch'
ary = [['al', 'al'], ['martha', 'marhta'], ['jones', 'johnson'], ['abcvwxyz', 'cabvwxyz'], ['dwayne', 'duane'], ['dixon', 'dicksonx'], ['fvie', 'ten']]

n = 10000
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 #{JaroWinkler::VERSION}" do
n.times{ ary.each{ |str1, str2| JaroWinkler.distance(str1, str2) } }
x.report "jaro_winkler (#{`git rev-parse --short HEAD`.chop!})" do
n.times { ary.each { |str1, str2| JaroWinkler.distance(str1, str2) } }
end

x.report "fuzzystringmatch #{Gem.loaded_specs['fuzzy-string-match'].version}" do
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 { ary.each { |str1, str2| jarow.getDistance(str1, str2) } }
end
end

0 comments on commit e6b93fb

Please sign in to comment.