File: localization_performance_test.rb

package info (click to toggle)
ruby-stringex 2.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,220 kB
  • sloc: ruby: 3,749; makefile: 5
file content (24 lines) | stat: -rw-r--r-- 801 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require "test_helper"
require 'stringex'
require 'i18n'
require 'benchmark'

class LocalizationPerformanceTest < Test::Unit::TestCase
  def setup
    I18n.locale = :en
    Stringex::Localization.reset!
  end

  def test_i18n_performance
    Stringex::Localization.backend = :internal
    internal_time = Benchmark.realtime { 100.times{ "alskdjfal".to_url } }

    Stringex::Localization.backend = :i18n
    i18n_time = Benchmark.realtime { 100.times{ "alskdjfal".to_url } }

    percentage_difference = ((i18n_time - internal_time) / internal_time) * 100
    allowed_difference = 25

    assert percentage_difference <= allowed_difference, "The I18n backend is #{percentage_difference.to_i} percent slower than the internal backend. The allowed difference is #{allowed_difference} percent."
  end
end