Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial implementation of benchmarks.

  • Loading branch information...
commit f9b5b9b113097724638bdab96862ffa404e67e70 1 parent 5964058
@josevalim josevalim authored
Showing with 200 additions and 0 deletions.
  1. +143 −0 benchmark/example.yml
  2. +57 −0 benchmark/run.rb
View
143 benchmark/example.yml
@@ -0,0 +1,143 @@
+en:
+ first: "First"
+ activerecord:
+ errors:
+ messages:
+ inclusion: "is not included in the list"
+ exclusion: "is reserved"
+ invalid: "is invalid"
+ confirmation: "doesn't match confirmation"
+ accepted: "must be accepted"
+ empty: "can't be empty"
+ blank: "can't be blank"
+ too_long: "is too long (maximum is {{count}} characters)"
+ too_short: "is too short (minimum is {{count}} characters)"
+ wrong_length: "is the wrong length (should be {{count}} characters)"
+ taken: "has already been taken"
+ not_a_number: "is not a number"
+ greater_than: "must be greater than {{count}}"
+ greater_than_or_equal_to: "must be greater than or equal to {{count}}"
+ equal_to: "must be equal to {{count}}"
+ less_than: "must be less than {{count}}"
+ less_than_or_equal_to: "must be less than or equal to {{count}}"
+ odd: "must be odd"
+ even: "must be even"
+ record_invalid: "Validation failed: {{errors}}"
+
+ models:
+ user:
+ blank: "This is a custom blank message for {{model}}: {{attribute}}"
+ attributes:
+ login:
+ blank: "This is a custom blank message for User login"
+
+
+ models:
+ user: "Dude"
+
+ attributes:
+ user:
+ login: "Handle"
+
+ date:
+ formats:
+ # Use the strftime parameters for formats.
+ # When no format has been given, it uses default.
+ # You can provide other formats here if you like!
+ default: "%Y-%m-%d"
+ short: "%b %d"
+ long: "%B %d, %Y"
+
+ day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
+ abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
+
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
+ month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
+ abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
+ # Used in date_select and datime_select.
+ order: [ :year, :month, :day ]
+
+ time:
+ formats:
+ default: "%a, %d %b %Y %H:%M:%S %z"
+ short: "%d %b %H:%M"
+ long: "%B %d, %Y %H:%M"
+ am: "am"
+ pm: "pm"
+
+ support:
+ array:
+ words_connector: ", "
+ two_words_connector: " and "
+ last_word_connector: ", and "
+
+ activemodel:
+ errors:
+ messages:
+ inclusion: "is not included in the list"
+ exclusion: "is reserved"
+ invalid: "is invalid"
+ confirmation: "doesn't match confirmation"
+ accepted: "must be accepted"
+ empty: "can't be empty"
+ blank: "can't be blank"
+ too_long: "is too long (maximum is {{count}} characters)"
+ too_short: "is too short (minimum is {{count}} characters)"
+ wrong_length: "is the wrong length (should be {{count}} characters)"
+ taken: "has already been taken"
+ not_a_number: "is not a number"
+ greater_than: "must be greater than {{count}}"
+ greater_than_or_equal_to: "must be greater than or equal to {{count}}"
+ equal_to: "must be equal to {{count}}"
+ less_than: "must be less than {{count}}"
+ less_than_or_equal_to: "must be less than or equal to {{count}}"
+ odd: "must be odd"
+ even: "must be even"
+ record_invalid: "Validation failed: {{errors}}"
+
+ models:
+ user:
+ blank: "This is a custom blank message for {{model}}: {{attribute}}"
+ attributes:
+ login:
+ blank: "This is a custom blank message for User login"
+
+ models:
+ user: "Dude"
+
+ attributes:
+ user:
+ login: "Handle"
+
+ model_data:
+ date:
+ formats:
+ # Use the strftime parameters for formats.
+ # When no format has been given, it uses default.
+ # You can provide other formats here if you like!
+ default: "%Y-%m-%d"
+ short: "%b %d"
+ long: "%B %d, %Y"
+
+ day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
+ abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
+
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
+ month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
+ abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
+ # Used in date_select and datime_select.
+ order: [ :year, :month, :day ]
+
+ time:
+ formats:
+ default: "%a, %d %b %Y %H:%M:%S %z"
+ short: "%d %b %H:%M"
+ long: "%B %d, %Y %H:%M"
+ am: "am"
+ pm: "pm"
+
+ support:
+ array:
+ words_connector: ", "
+ two_words_connector: " and "
+ last_word_connector: ", and "
View
57 benchmark/run.rb
@@ -0,0 +1,57 @@
+$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
+
+require 'i18n'
+require 'i18n/core_ext/object/meta_class'
+require 'benchmark'
+require 'yaml'
+
+YAML_HASH = YAML.load_file(File.expand_path("example.yml", File.dirname(__FILE__)))
+
+def create_backend(*modules)
+ Class.new do
+ modules.unshift(I18n::Backend::Base)
+ modules.each { |m| include m }
+ end
+end
+
+BACKENDS = []
+BACKENDS << (SimpleBackend = create_backend)
+BACKENDS << (FastBackend = create_backend(I18n::Backend::Fast))
+
+BACKENDS.each do |backend|
+ puts backend.name
+ I18n.backend = backend.new
+
+ print "Store translations time: "
+ puts Benchmark.realtime {
+ I18n.backend.store_translations *(YAML_HASH.to_a.first)
+ I18n.backend.translate :en, :first
+ } * 1000
+
+ print "Translate a key (size 3): "
+ puts Benchmark.realtime {
+ I18n.backend.translate :en, :"activerecord.models.user"
+ } * 1000
+
+ print "Translate a key (size 5): "
+ puts Benchmark.realtime {
+ I18n.backend.translate :en, :"activerecord.errors.models.user.blank"
+ } * 1000
+
+ print "Translate a key (size 7): "
+ puts Benchmark.realtime {
+ I18n.backend.translate :en, :"activerecord.errors.models.user.attributes.login.blank"
+ } * 1000
+
+ print "Translate with default: "
+ puts Benchmark.realtime {
+ I18n.backend.translate :en, :"activerecord.models.another", :default => "Another"
+ } * 1000
+
+ print "Translate subtree: "
+ puts Benchmark.realtime {
+ I18n.backend.translate :en, :"activerecord.errors.messages"
+ } * 1000
+
+ puts
+end
Please sign in to comment.
Something went wrong with that request. Please try again.