Skip to content

Instantly share code, notes, and snippets.

@thedarkone
Created March 17, 2009 17:28
Show Gist options
  • Save thedarkone/80667 to your computer and use it in GitHub Desktop.
Save thedarkone/80667 to your computer and use it in GitHub Desktop.
$:.unshift "lib"
require 'i18n'
require "benchmark"
def with_fast?; defined?(I18n::Backend::Fast); end
str = 'abc {{a}}, {{b}}'
f = I18n::Backend::Fast.new if with_fast?
s = I18n::Backend::Simple.new
[f, s].compact.each {|b| b.store_translations 'en', :foo => {:bar => {:bax => {:buz => 'buz'}, :tr => str}, :baz => 'baz'}}
TESTS = 200_000
Benchmark.bmbm do |results|
results.report("s.t(:'foo.bar.bax.buz')") do
TESTS.times { s.translate(:en, :'foo.bar.bax.buz') }
end
results.report("f.t(:'foo.bar.bax.buz')") do
TESTS.times { f.translate(:en, :'foo.bar.bax.buz') }
end if with_fast?
results.report("s.t(:'foo.bar.tr', :a => 'A', :b => 'B')") do
TESTS.times { s.translate(:en, :'foo.bar.tr', :a => 'A', :b => 'B') }
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 if with_fast?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment