Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created August 27, 2008 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattetti/7471 to your computer and use it in GitHub Desktop.
Save mattetti/7471 to your computer and use it in GitHub Desktop.
| simple backend using #translate | Ruby hash | #1/#2 |
--------------------------------------------------------------------------------------------------
lookup with locale given x100000 | 3.560 | 0.061 | 58.54x |
| no key | key with scope | hash key being nil | #1/#3 |
----------------------------------------------------------------------------------------------------
lookup with no key given x100000 | 1.422 | 3.577 | 0.045 | 31.77x |
require "rubygems"
require "rbench"
$:.unshift "./../lib"
require File.dirname(__FILE__) + '/../lib/i18n'
require 'time'
TIMES = 100_000
RBench.run(TIMES) do
column :times
column :one, :title => "simple backend using #translate"
column :two, :title => "Ruby hash"
column :diff, :title => "#1/#2", :compare => [:one,:two]
report "lookup with locale given" do
@backend = I18n::Backend::Simple.new
@backend.store_translations 'en-US', :foo => {:bar => 'bar', :baz => 'baz'}
@memory_hash = {:'en-US' => {:foo => {:bar => 'bar', :baz => 'baz'}} }
one { @backend.translate('en-US', :bar, :scope => [:foo]) }
two { @memory_hash[:'en-US'][:foo][:bar] }
end
end
RBench.run(TIMES) do
column :times
column :one, :title => "no key"
column :two, :title => "key with scope"
column :three, :title => "hash key being nil"
column :diff, :title => "#1/#3", :compare => [:one,:three]
report "lookup with no key given" do
@backend = I18n::Backend::Simple.new
@backend.store_translations 'en-US', :foo => {:bar => 'bar', :baz => 'baz'}
@memory_hash = {:'en-US' => {:foo => {:bar => 'bar', :baz => 'baz'}} }
one { @backend.translate('en-US', nil, :default => 'default') }
two { @backend.translate('en-US', :bar, :scope => [:foo]) }
three { @memory_hash[:test] }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment