aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gems/gettext-2.1.0/benchmark/benchmark.rb
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gems/gettext-2.1.0/benchmark/benchmark.rb')
-rw-r--r--vendor/gems/gettext-2.1.0/benchmark/benchmark.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/gems/gettext-2.1.0/benchmark/benchmark.rb b/vendor/gems/gettext-2.1.0/benchmark/benchmark.rb
new file mode 100644
index 000000000..dbe7fc443
--- /dev/null
+++ b/vendor/gems/gettext-2.1.0/benchmark/benchmark.rb
@@ -0,0 +1,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 "