Created
August 31, 2018 17:46
-
-
Save markets/eab1d4a82d22146b577a085d00f1185d to your computer and use it in GitHub Desktop.
MiniI18n gem benchmarking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
require 'mini_i18n' | |
require 'i18n' | |
translations_path = File.expand_path('./spec/fixtures/locales/*') | |
# Init MiniI18n | |
MiniI18n.load_translations(translations_path) | |
# Init I18n | |
I18n.load_path = Dir[translations_path] | |
Benchmark.ips do |x| | |
x.report("mini_i18n - translate") { MiniI18n.t(:hello) } | |
x.report("i18n - translate") { I18n.t(:hello) } | |
x.compare! | |
end | |
Benchmark.ips do |x| | |
x.report("mini_i18n - translate nested key") { MiniI18n.t('second_level.hello') } | |
x.report("i18n - translate nested key") { I18n.t('second_level.hello') } | |
x.compare! | |
end | |
Benchmark.ips do |x| | |
x.report("mini_i18n - translate interpolation") { MiniI18n.t('hello_interpolation', name: 'world') } | |
x.report("i18n - translate interpolation") { I18n.t('hello_interpolation', name: 'world') } | |
x.compare! | |
end | |
Benchmark.ips do |x| | |
date = Date.new(2018, 8, 7) | |
x.report("mini_i18n - localize date") { MiniI18n.l(date) } | |
x.report("i18n - localize date") { I18n.l(date) } | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results on my machine (Mac Mini i5 2.5GHz, 8 GB DDR3):
MiniI18n
is x2+ faster thanI18n
🚀 🌐