Skip to content

Instantly share code, notes, and snippets.

@thedarkone
Created December 6, 2009 12:32
Show Gist options
  • Save thedarkone/250199 to your computer and use it in GitHub Desktop.
Save thedarkone/250199 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -KU
$:.unshift(File.join(File.dirname(__FILE__), "../lib")).unshift('lib')
require 'i18n'
require 'benchmark'
f = I18n::Backend::Fast.new
I18n.backend = f
interpolation = 'abc {{a}}, {{b}}'
f.store_translations 'en', :foo => {:bar => {:bax => {:buz => 'buz'}, :tr => interpolation}, :baz => 'baz'}
puts f.translate(:en, :'foo.bar.bax.buz')
puts I18n.translate(:'foo.bar.bax.buz')
puts f.translate(:en, :'foo.bar.tr', :a => 'A', :b => 'B')
puts I18n.translate(:'foo.bar.tr', :a => 'A', :b => 'B')
TESTS = 200_000
Benchmark.bmbm do |results|
results.report("f.t(:'foo.bar.bax.buz')") do
TESTS.times { f.translate(:en, :'foo.bar.bax.buz') }
end
results.report("I18n.t(:'foo.bar.bax.buz')") do
TESTS.times { I18n.translate(:'foo.bar.bax.buz') }
end
results.report("f.t(:'foo.bar.tr', :a => 'A', :b => 'B')") do
TESTS.times { f.translate(:en, :'foo.bar.tr', :a => 'A', :b => 'B') }
end
results.report("I18n.t(:'foo.bar.tr', :a => 'A', :b => 'B')") do
TESTS.times { I18n.translate(:'foo.bar.tr', :a => 'A', :b => 'B') }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment