Skip to content

Instantly share code, notes, and snippets.

@markets
Created August 31, 2018 17:46
Show Gist options
  • Save markets/eab1d4a82d22146b577a085d00f1185d to your computer and use it in GitHub Desktop.
Save markets/eab1d4a82d22146b577a085d00f1185d to your computer and use it in GitHub Desktop.
MiniI18n gem benchmarking
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
@markets
Copy link
Author

markets commented Aug 31, 2018

Results on my machine (Mac Mini i5 2.5GHz, 8 GB DDR3):

Warming up --------------------------------------
mini_i18n - translate
                        12.095k i/100ms
    i18n - translate     5.588k i/100ms
Calculating -------------------------------------
mini_i18n - translate
                        143.509k (±14.5%) i/s -    701.510k in   5.027039s
    i18n - translate     67.776k (± 7.4%) i/s -    340.868k in   5.057750s

Comparison:
mini_i18n - translate:   143508.5 i/s
    i18n - translate:    67775.9 i/s - 2.12x  slower

Warming up --------------------------------------
mini_i18n - translate nested key
                        12.782k i/100ms
i18n - translate nested key
                         5.492k i/100ms
Calculating -------------------------------------
mini_i18n - translate nested key
                        138.136k (±15.4%) i/s -    690.228k in   5.161657s
i18n - translate nested key
                         67.829k (± 5.2%) i/s -    340.504k in   5.034393s

Comparison:
mini_i18n - translate nested key:   138135.8 i/s
i18n - translate nested key:    67828.8 i/s - 2.04x  slower

Warming up --------------------------------------
mini_i18n - translate interpolation
                         8.067k i/100ms
i18n - translate interpolation
                         3.053k i/100ms
Calculating -------------------------------------
mini_i18n - translate interpolation
                         78.566k (±16.4%) i/s -    387.216k in   5.066746s
i18n - translate interpolation
                         33.009k (±16.6%) i/s -    158.756k in   5.011990s

Comparison:
mini_i18n - translate interpolation:    78566.3 i/s
i18n - translate interpolation:    33008.5 i/s - 2.38x  slower

Warming up --------------------------------------
mini_i18n - localize date
                         5.358k i/100ms
i18n - localize date     1.254k i/100ms
Calculating -------------------------------------
mini_i18n - localize date
                         61.601k (± 9.0%) i/s -    310.764k in   5.086789s
i18n - localize date     13.021k (± 6.1%) i/s -     65.208k in   5.027407s

Comparison:
mini_i18n - localize date:    61601.4 i/s
i18n - localize date:    13020.5 i/s - 4.73x  slower

MiniI18n is x2+ faster than I18n 🚀 🌐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment