Skip to content
This repository
Browse code

Initial implementation of benchmarks.

  • Loading branch information...
commit f9b5b9b113097724638bdab96862ffa404e67e70 1 parent 5964058
José Valim authored December 29, 2009
143  benchmark/example.yml
... ...
@@ -0,0 +1,143 @@
  1
+en:
  2
+  first: "First"
  3
+  activerecord:
  4
+    errors:
  5
+      messages:
  6
+        inclusion: "is not included in the list"
  7
+        exclusion: "is reserved"
  8
+        invalid: "is invalid"
  9
+        confirmation: "doesn't match confirmation"
  10
+        accepted: "must be accepted"
  11
+        empty: "can't be empty"
  12
+        blank: "can't be blank"
  13
+        too_long: "is too long (maximum is {{count}} characters)"
  14
+        too_short: "is too short (minimum is {{count}} characters)"
  15
+        wrong_length: "is the wrong length (should be {{count}} characters)"
  16
+        taken: "has already been taken"
  17
+        not_a_number: "is not a number"
  18
+        greater_than: "must be greater than {{count}}"
  19
+        greater_than_or_equal_to: "must be greater than or equal to {{count}}"
  20
+        equal_to: "must be equal to {{count}}"
  21
+        less_than: "must be less than {{count}}"
  22
+        less_than_or_equal_to: "must be less than or equal to {{count}}"
  23
+        odd: "must be odd"
  24
+        even: "must be even"
  25
+        record_invalid: "Validation failed: {{errors}}"
  26
+
  27
+      models:
  28
+        user:
  29
+          blank: "This is a custom blank message for {{model}}: {{attribute}}"
  30
+          attributes:
  31
+            login:
  32
+              blank: "This is a custom blank message for User login"
  33
+        
  34
+
  35
+    models:
  36
+      user: "Dude"
  37
+    
  38
+    attributes:
  39
+      user:
  40
+        login: "Handle"
  41
+
  42
+  date:
  43
+    formats:
  44
+      # Use the strftime parameters for formats.
  45
+      # When no format has been given, it uses default.
  46
+      # You can provide other formats here if you like!
  47
+      default: "%Y-%m-%d"
  48
+      short: "%b %d"
  49
+      long: "%B %d, %Y"
  50
+
  51
+    day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
  52
+    abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
  53
+
  54
+    # Don't forget the nil at the beginning; there's no such thing as a 0th month
  55
+    month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
  56
+    abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
  57
+    # Used in date_select and datime_select.
  58
+    order: [ :year, :month, :day ]
  59
+
  60
+  time:
  61
+    formats:
  62
+      default: "%a, %d %b %Y %H:%M:%S %z"
  63
+      short: "%d %b %H:%M"
  64
+      long: "%B %d, %Y %H:%M"
  65
+    am: "am"
  66
+    pm: "pm"
  67
+
  68
+  support:
  69
+    array:
  70
+      words_connector: ", "
  71
+      two_words_connector: " and "
  72
+      last_word_connector: ", and "
  73
+
  74
+  activemodel:
  75
+    errors:
  76
+      messages:
  77
+        inclusion: "is not included in the list"
  78
+        exclusion: "is reserved"
  79
+        invalid: "is invalid"
  80
+        confirmation: "doesn't match confirmation"
  81
+        accepted: "must be accepted"
  82
+        empty: "can't be empty"
  83
+        blank: "can't be blank"
  84
+        too_long: "is too long (maximum is {{count}} characters)"
  85
+        too_short: "is too short (minimum is {{count}} characters)"
  86
+        wrong_length: "is the wrong length (should be {{count}} characters)"
  87
+        taken: "has already been taken"
  88
+        not_a_number: "is not a number"
  89
+        greater_than: "must be greater than {{count}}"
  90
+        greater_than_or_equal_to: "must be greater than or equal to {{count}}"
  91
+        equal_to: "must be equal to {{count}}"
  92
+        less_than: "must be less than {{count}}"
  93
+        less_than_or_equal_to: "must be less than or equal to {{count}}"
  94
+        odd: "must be odd"
  95
+        even: "must be even"
  96
+        record_invalid: "Validation failed: {{errors}}"
  97
+
  98
+      models:
  99
+        user:
  100
+          blank: "This is a custom blank message for {{model}}: {{attribute}}"
  101
+          attributes:
  102
+            login:
  103
+              blank: "This is a custom blank message for User login"
  104
+
  105
+    models:
  106
+      user: "Dude"
  107
+
  108
+    attributes:
  109
+      user:
  110
+        login: "Handle"
  111
+
  112
+  model_data:
  113
+    date:
  114
+      formats:
  115
+        # Use the strftime parameters for formats.
  116
+        # When no format has been given, it uses default.
  117
+        # You can provide other formats here if you like!
  118
+        default: "%Y-%m-%d"
  119
+        short: "%b %d"
  120
+        long: "%B %d, %Y"
  121
+
  122
+      day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
  123
+      abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
  124
+
  125
+      # Don't forget the nil at the beginning; there's no such thing as a 0th month
  126
+      month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
  127
+      abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
  128
+      # Used in date_select and datime_select.
  129
+      order: [ :year, :month, :day ]
  130
+
  131
+    time:
  132
+      formats:
  133
+        default: "%a, %d %b %Y %H:%M:%S %z"
  134
+        short: "%d %b %H:%M"
  135
+        long: "%B %d, %Y %H:%M"
  136
+      am: "am"
  137
+      pm: "pm"
  138
+
  139
+    support:
  140
+      array:
  141
+        words_connector: ", "
  142
+        two_words_connector: " and "
  143
+        last_word_connector: ", and "
57  benchmark/run.rb
... ...
@@ -0,0 +1,57 @@
  1
+$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
  2
+
  3
+require 'i18n'
  4
+require 'i18n/core_ext/object/meta_class'
  5
+require 'benchmark'
  6
+require 'yaml'
  7
+
  8
+YAML_HASH = YAML.load_file(File.expand_path("example.yml", File.dirname(__FILE__)))
  9
+
  10
+def create_backend(*modules)
  11
+  Class.new do
  12
+    modules.unshift(I18n::Backend::Base)
  13
+    modules.each { |m| include m }
  14
+  end
  15
+end
  16
+
  17
+BACKENDS = []
  18
+BACKENDS << (SimpleBackend = create_backend)
  19
+BACKENDS << (FastBackend   = create_backend(I18n::Backend::Fast))
  20
+
  21
+BACKENDS.each do |backend|
  22
+  puts backend.name
  23
+  I18n.backend = backend.new
  24
+
  25
+  print "Store translations time:  "
  26
+  puts Benchmark.realtime {
  27
+    I18n.backend.store_translations *(YAML_HASH.to_a.first)
  28
+    I18n.backend.translate :en, :first
  29
+  } * 1000
  30
+
  31
+  print "Translate a key (size 3): "
  32
+  puts Benchmark.realtime {
  33
+    I18n.backend.translate :en, :"activerecord.models.user"
  34
+  } * 1000
  35
+
  36
+  print "Translate a key (size 5): "
  37
+  puts Benchmark.realtime {
  38
+    I18n.backend.translate :en, :"activerecord.errors.models.user.blank"
  39
+  } * 1000
  40
+
  41
+  print "Translate a key (size 7): "
  42
+  puts Benchmark.realtime {
  43
+    I18n.backend.translate :en, :"activerecord.errors.models.user.attributes.login.blank"
  44
+  } * 1000
  45
+
  46
+  print "Translate with default:   "
  47
+  puts Benchmark.realtime {
  48
+    I18n.backend.translate :en, :"activerecord.models.another", :default => "Another"
  49
+  } * 1000
  50
+
  51
+  print "Translate subtree:        "
  52
+  puts Benchmark.realtime {
  53
+    I18n.backend.translate :en, :"activerecord.errors.messages"
  54
+  } * 1000
  55
+
  56
+  puts
  57
+end

0 notes on commit f9b5b9b

Please sign in to comment.
Something went wrong with that request. Please try again.