i18nema 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +23 -24
  2. data/lib/i18nema.rb +17 -14
  3. metadata +2 -2
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Fast I18n backend to keep things running smoothly.
4
4
 
5
5
  I18nema is a drop-in replacement for I18n::Backend::Simple, for faster
6
- lookups (2x!) and quicker GC runs (ymmv). Translations are stored
6
+ lookups (15-20%) and quicker GC runs (ymmv). Translations are stored
7
7
  outside of the ruby heap, and lookups happen in C (rather than the usual
8
8
  inject on nested ruby hashes).
9
9
 
@@ -52,13 +52,13 @@ is nicer on ObjectSpace than vanilla I18n.
52
52
 
53
53
  ### Faster Translation Lookups
54
54
 
55
- Simple lookups (i.e. no options or interpolation) take about 55% less
56
- time, and that holds true no matter how deeply scoped your keys are
57
- (e.g. `foo.bar.baz.lol`).
55
+ Simple lookups (i.e. no options or interpolation) take a bit over 15%
56
+ less time.
58
57
 
59
- Lookups with options are also faster (about 35% less time). The gains
60
- aren't quite as big there yet, since proportionally more of the time is
61
- spent in unoptimized places like `I18n#interpolate`.
58
+ Lookups with options see slightly bigger gains (over 20% less time), in
59
+ part due to some speedups on the ruby side of things (I18n uses
60
+ `Hash#except`, which is quite slow when you have a long list of
61
+ arguments).
62
62
 
63
63
  ## Show me the benchmarks
64
64
 
@@ -72,37 +72,36 @@ e.g. `I18n.t('foo') -> 1`, `I18n.t('foo.bar') -> 2`
72
72
  #### I18nema
73
73
 
74
74
  user system total real
75
- translate(1): 0.960000 0.010000 0.970000 ( 0.963384)
76
- translate(2): 1.070000 0.010000 1.080000 ( 1.068789)
77
- translate(3): 1.080000 0.000000 1.080000 ( 1.083826)
78
- translate(4): 1.260000 0.010000 1.270000 ( 1.263967)
75
+ translate(1): 0.900000 0.010000 0.910000 ( 0.910228)
76
+ translate(2): 1.010000 0.010000 1.020000 ( 1.009545)
77
+ translate(3): 1.020000 0.010000 1.030000 ( 1.028098)
78
+ translate(4): 1.210000 0.000000 1.210000 ( 1.214737)
79
79
 
80
80
  #### I18n
81
81
 
82
82
  user system total real
83
- translate(1): 2.140000 0.000000 2.140000 ( 2.137579)
84
- translate(2): 2.380000 0.000000 2.380000 ( 2.382720)
85
- translate(3): 2.420000 0.000000 2.420000 ( 2.428245)
86
- translate(4): 2.510000 0.000000 2.510000 ( 2.514133)
83
+ translate(1): 1.000000 0.000000 1.000000 ( 1.007367)
84
+ translate(2): 1.260000 0.000000 1.260000 ( 1.268323)
85
+ translate(3): 1.320000 0.000000 1.320000 ( 1.315132)
86
+ translate(4): 1.390000 0.010000 1.400000 ( 1.393478)
87
87
 
88
88
  ### `translate` with options (locale, interpolation)
89
89
 
90
90
  #### I18nema
91
91
 
92
92
  user system total real
93
- translate(1): 1.770000 0.000000 1.770000 ( 1.771934)
94
- translate(2): 1.870000 0.010000 1.880000 ( 1.880586)
95
- translate(3): 1.890000 0.000000 1.890000 ( 1.893065)
96
- translate(4): 2.080000 0.000000 2.080000 ( 2.083093)
93
+ translate(1): 0.950000 0.000000 0.950000 ( 0.943904)
94
+ translate(2): 1.040000 0.000000 1.040000 ( 1.036595)
95
+ translate(3): 1.060000 0.010000 1.070000 ( 1.059588)
96
+ translate(4): 1.240000 0.000000 1.240000 ( 1.237322)
97
97
 
98
98
  #### I18n
99
99
 
100
100
  user system total real
101
- translate(1): 2.720000 0.000000 2.720000 ( 2.720541)
102
- translate(2): 2.950000 0.010000 2.960000 ( 2.953175)
103
- translate(3): 3.010000 0.010000 3.020000 ( 3.028288)
104
- translate(4): 3.120000 0.010000 3.130000 ( 3.117135)
105
-
101
+ translate(1): 1.090000 0.000000 1.090000 ( 1.099866)
102
+ translate(2): 1.360000 0.000000 1.360000 ( 1.364869)
103
+ translate(3): 1.430000 0.000000 1.430000 ( 1.425103)
104
+ translate(4): 1.500000 0.010000 1.510000 ( 1.500952)
106
105
 
107
106
  ## OK, so what's the catch?
108
107
 
data/lib/i18nema.rb CHANGED
@@ -4,20 +4,7 @@ require File.dirname(__FILE__) + '/i18nema/core_ext/hash'
4
4
  require File.dirname(__FILE__) + '/i18nema/i18nema'
5
5
 
6
6
  module I18nema
7
- class Backend
8
- include I18n::Backend::Base
9
-
10
- def store_translations(locale, data, options = {})
11
- # TODO: make this moar awesome
12
- @initialized = true
13
- load_yml_string({locale => data}.deep_stringify_keys.to_yaml)
14
- end
15
-
16
- def init_translations
17
- load_translations
18
- @initialized = true
19
- end
20
-
7
+ module CoreMethods
21
8
  RESERVED_KEY_MAP = Hash[I18n::RESERVED_KEYS.map{|k|[k,true]}]
22
9
 
23
10
  def translate(locale, key, options = {})
@@ -41,6 +28,22 @@ module I18nema
41
28
  entry = interpolate(locale, entry, values) if values
42
29
  entry
43
30
  end
31
+ end
32
+
33
+ class Backend
34
+ include I18n::Backend::Base
35
+ include CoreMethods # defined in a module so that other modules (e.g. I18n::Backend::Fallbacks) can override them
36
+
37
+ def store_translations(locale, data, options = {})
38
+ # TODO: make this moar awesome
39
+ @initialized = true
40
+ load_yml_string({locale => data}.deep_stringify_keys.to_yaml)
41
+ end
42
+
43
+ def init_translations
44
+ load_translations
45
+ @initialized = true
46
+ end
44
47
 
45
48
  protected
46
49
  def load_file(filename)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18nema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-04 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n