-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark
executable file
·61 lines (48 loc) · 2.37 KB
/
benchmark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env ruby
require "bundler/setup"
require "active_normalizer"
require "active_normalizer/normalizers/unf"
require "active_normalizer/normalizers/unicode"
require "active_normalizer/normalizers/ruby"
require "active_normalizer/normalizers/unicode_utils"
require "active_normalizer/normalizers/active_support"
require "benchmark/ips"
class GCSuite
def warming(*); run_gc; end
def running(*); run_gc; end
def warmup_stats(*); end
def add_report(*); end
private
def run_gc
GC.enable
GC.start
GC.disable
end
end
def benchmark(input, suite)
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
x.config(suite: suite)
x.report("UNF") { ActiveNormalizer::Normalizers::UNF.new(:nfkc).run(input) }
x.report("Unicode") { ActiveNormalizer::Normalizers::Unicode.new(:nfkc).run(input) }
x.report("Ruby") { ActiveNormalizer::Normalizers::Ruby.new(:nfkc).run(input) }
x.report("UnicodeUtils") { ActiveNormalizer::Normalizers::UnicodeUtils.new(:nfkc).run(input) }
x.report("ActiveSupport") { ActiveNormalizer::Normalizers::ActiveSupport.new(:nfkc).run(input) }
x.compare!
end
Benchmark.ips do |x|
x.config(time: 30, warmup: 10)
x.config(suite: suite)
x.report("UNF") { ActiveNormalizer::Normalizers::UNF.new(:nfkc).run(input) }
x.report("Unicode") { ActiveNormalizer::Normalizers::Unicode.new(:nfkc).run(input) }
x.report("Ruby") { ActiveNormalizer::Normalizers::Ruby.new(:nfkc).run(input) }
x.report("UnicodeUtils") { ActiveNormalizer::Normalizers::UnicodeUtils.new(:nfkc).run(input) }
x.report("ActiveSupport") { ActiveNormalizer::Normalizers::ActiveSupport.new(:nfkc).run(input) }
x.compare!
end
end
suite = GCSuite.new
puts "Benchmarking simple string: 800ー12345"
benchmark("800ー12345", suite)
puts "\nBenchmarking longer string: ㍻㍼㍽㍾㌀㌁㌂㌃㌄㌅㌆㌇㌈㌉㌊㌋㌌㌍㌎㌏㌐㌑㌒㌓㌔㌕㌖㌗㌘㌙㌚㌛㌜㌝㌞㌟㌠㌡㌢㌣㌤㌥㌦㌧㌨㌩㌪㌫㌬㌭㌮㌯㌰㌱㌲㌳㌴㌵㌶㌷㌸㌹㌺㌻㌼㌽㌾㌿㍀㍁㍂㍃㍄㍅㍆㍇㍈㍉㍊㍋㍌㍍㍎㍏㍐㍑㍒㍓㍔㍕㍖㍗"
benchmark("㍻㍼㍽㍾㌀㌁㌂㌃㌄㌅㌆㌇㌈㌉㌊㌋㌌㌍㌎㌏㌐㌑㌒㌓㌔㌕㌖㌗㌘㌙㌚㌛㌜㌝㌞㌟㌠㌡㌢㌣㌤㌥㌦㌧㌨㌩㌪㌫㌬㌭㌮㌯㌰㌱㌲㌳㌴㌵㌶㌷㌸㌹㌺㌻㌼㌽㌾㌿㍀㍁㍂㍃㍄㍅㍆㍇㍈㍉㍊㍋㍌㍍㍎㍏㍐㍑㍒㍓㍔㍕㍖㍗", suite)