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
62
63
64
65
66
67
68
|
$:.unshift "../../locale/lib"
$:.unshift "../../gettext/lib"
#require 'rubygems'
require 'benchmark'
require 'gettext'
num = 100000
def memory
pid = Process.pid
map = `pmap -d #{pid}`
map.split("\n").last.strip.squeeze(' ').split(' ')[3].to_i
end
curr_mem = memory
class Test
include GetText
bindtextdomain("test1", :path => "../test/locale")
def test
_("language")
end
end
p GetText::VERSION
Benchmark.bm(25){|x|
x.report("bindtextdomain"){ num.times{|i|
GetText.bindtextdomain("test1", :path => "../test/locale")
#GetText.bindtextdomain("test1", "../test/locale")
} }
x.report("set_locale"){ num.times{|i|
GetText.locale = "ja"
} }
GetText.locale = "ja"
x.report("gettext ja"){ num.times{|i|
GetText._("language")
} }
GetText.locale = "en"
x.report("gettext en (not found)"){ num.times{|i|
GetText._("language")
} }
GetText.bindtextdomain("plural", :path => "../test/locale")
#GetText.bindtextdomain("plural", "../test/locale")
GetText.locale = "ja"
x.report("ngettext ja"){ (num / 2).times{|i|
GetText.n_("single", "plural", 1)
GetText.n_("single", "plural", 2)
} }
GetText.locale = "en"
x.report("ngettext en (not found)"){ (num / 2).times{|i|
GetText.n_("single", "plural", 1)
GetText.n_("single", "plural", 2)
} }
GetText.locale = "ja"
x.report("create object ja"){ num.times{|i|
Test.new.test
} }
GetText.locale = "en"
x.report("create object en"){ num.times{|i|
Test.new.test
} }
}
GC.start
puts "#{memory - curr_mem}K "
|