Sha256: 0d1325ab4f5551608542564cd8e539dfde8dee360a35313961b97ae7f09ad787

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

$:.unshift "../../locale/lib"
$:.unshift "../../gettext/lib"

#require 'rubygems'
require 'benchmark'
require 'gettext'

num = 100000

def memory
  pid = Process.pid
  map = `pmap -d #{pid}`
  map.split("\n").last.strip.squeeze(' ').split(' ')[3].to_i
end

curr_mem = memory

class Test
  include GetText
  bindtextdomain("test1", :path => "../test/locale")
  def test
    _("language")
  end
end

p GetText::VERSION
Benchmark.bm(25){|x|
  x.report("bindtextdomain"){ num.times{|i|
    GetText.bindtextdomain("test1", :path => "../test/locale")
    #GetText.bindtextdomain("test1", "../test/locale")
  } }
  x.report("set_locale"){ num.times{|i|
    GetText.locale = "ja"
  } }
  GetText.locale = "ja"
  x.report("gettext ja"){ num.times{|i|
    GetText._("language")
  } }
  GetText.locale = "en"
  x.report("gettext en (not found)"){ num.times{|i|
    GetText._("language")
  } }

  GetText.bindtextdomain("plural", :path => "../test/locale")
  #GetText.bindtextdomain("plural", "../test/locale")
  GetText.locale = "ja"
  x.report("ngettext ja"){ (num / 2).times{|i|
    GetText.n_("single", "plural", 1)
    GetText.n_("single", "plural", 2)
  } }
  GetText.locale = "en"
  x.report("ngettext en (not found)"){ (num / 2).times{|i|
    GetText.n_("single", "plural", 1)
    GetText.n_("single", "plural", 2)
  } }

  GetText.locale = "ja"
  x.report("create object ja"){ num.times{|i|
      Test.new.test
  } }
  GetText.locale = "en"
  x.report("create object en"){ num.times{|i|
      Test.new.test
  } }
}

GC.start
puts "#{memory - curr_mem}K "

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
fair-gettext-2.0.7 benchmark/benchmark.rb
fair-gettext-2.0.6 benchmark/benchmark.rb
fair-gettext-2.0.5 benchmark/benchmark.rb
fair-gettext-2.0.4 benchmark/benchmark.rb
fair-gettext-2.0.3 benchmark/benchmark.rb
fair-gettext-2.0.2 benchmark/benchmark.rb
gettext-2.1.0 benchmark/benchmark.rb