memoist 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e0b4aa15826f19afb39c63ff8c7706abc4e53a2
4
+ data.tar.gz: a376c4966fb18ef1ea0b38df8a6ab5c6d4af975c
5
+ SHA512:
6
+ metadata.gz: 5dca60e9396ec42bc701b7891151ef5e27baad27dc90a3d4dfd87f4510ba5f4eadfbe87755482c079c1d6c5591109fdd2bfc04f0a0618892af75b016420b69e3
7
+ data.tar.gz: 23a7bfc511cd96f10d80432f0514582e795eab96beba8ea3b4ce5bba6721e0eb373ee15fb6f63bb5f793475a77336132da62f4f5e1cacb179fdbf9a6104982da
@@ -0,0 +1,143 @@
1
+ <<-INTRO
2
+
3
+ Question:
4
+ How fast are these simple use case of memoisation
5
+
6
+ hash = {}
7
+ hash[:name] = "Peter"
8
+ hash[:age] = 23
9
+ hash[:hair_colour] = "black"
10
+ hash
11
+
12
+ {}.tap do |hash|
13
+ hash[:name] = "Peter"
14
+ hash[:age] = 23
15
+ hash[:hair_colour] = "black"
16
+ end
17
+
18
+ Answer:
19
+ Not really
20
+
21
+ user system total real
22
+ local variable 14.170000 0.060000 14.230000 ( 14.223995)
23
+ tap 15.440000 0.040000 15.480000 ( 15.492474)
24
+
25
+ INTRO
26
+
27
+ require 'memoist'
28
+
29
+ class Foo
30
+ extend Memoist
31
+
32
+ def memoized
33
+ 42
34
+ end
35
+ memoize :memoized
36
+
37
+ def memoized_manually
38
+ @memoized_manually ||= 42
39
+ end
40
+
41
+ def memoized_manually_with_defined
42
+ unless defined?(@memoized_manually_with_defined)
43
+ @memoized_manually_with_defined = 42
44
+ end
45
+ @memoized_manually_with_defined
46
+ end
47
+
48
+ def raw
49
+ 42
50
+ end
51
+
52
+ def memoized_with_arg(arg)
53
+ 42
54
+ end
55
+ memoize :memoized_with_arg
56
+ end
57
+
58
+ require 'benchmark'
59
+
60
+ TIMES = 10_000_000
61
+
62
+ Benchmark.bm(40) do |x|
63
+ x.report "calling memoized method" do
64
+ foo = Foo.new
65
+ TIMES.times do
66
+ foo.memoized
67
+ end
68
+ end
69
+
70
+ x.report "calling manually memoized method" do
71
+ foo = Foo.new
72
+ TIMES.times do
73
+ foo.memoized_manually
74
+ end
75
+ end
76
+
77
+ x.report "calling manually memoized (with defined?) method" do
78
+ foo = Foo.new
79
+ TIMES.times do
80
+ foo.memoized_manually_with_defined
81
+ end
82
+ end
83
+
84
+ x.report "calling non-memoized method" do
85
+ foo = Foo.new
86
+ TIMES.times do
87
+ foo.raw
88
+ end
89
+ end
90
+
91
+ x.report "calling memoized method - one time" do
92
+ TIMES.times do
93
+ foo = Foo.new
94
+ foo.memoized
95
+ end
96
+ end
97
+
98
+ x.report "calling manually memoized method - one time" do
99
+ TIMES.times do
100
+ foo = Foo.new
101
+ foo.memoized_manually
102
+ end
103
+ end
104
+
105
+ x.report "calling manually memoized (with defined?) method - one time" do
106
+ TIMES.times do
107
+ foo = Foo.new
108
+ foo.memoized_manually_with_defined
109
+ end
110
+ end
111
+
112
+ x.report "calling non-memoized method - one time" do
113
+ TIMES.times do
114
+ foo = Foo.new
115
+ foo.raw
116
+ end
117
+ end
118
+ x.report "re-loading memoized method" do
119
+ foo = Foo.new
120
+ TIMES.times do
121
+ foo.memoized(true)
122
+ end
123
+ end
124
+
125
+ comment = <<-COMMENT
126
+
127
+ x.report "calling memoized method with args" do
128
+ foo = Foo.new
129
+ TIMES.times do
130
+ foo.memoized_with_arg(1337)
131
+ end
132
+ end
133
+
134
+ x.report "calling memoized method with args - no cache" do
135
+ foo = Foo.new
136
+ TIMES.times do |i|
137
+ foo.memoized_with_arg(i)
138
+ end
139
+ end
140
+
141
+ COMMENT
142
+
143
+ end
metadata CHANGED
@@ -1,17 +1,11 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: memoist
3
- version: !ruby/object:Gem::Version
4
- hash: 59
5
- prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 0
10
- version: 0.9.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Joshua Peek
14
- - "Tarmo T\xC3\xA4nav"
8
+ - Tarmo Tänav
15
9
  - Jeremy Kemper
16
10
  - Eugene Pimenov
17
11
  - Xavier Noria
@@ -20,16 +14,14 @@ authors:
20
14
  - jeem
21
15
  - Jay Pignata
22
16
  - Damien Mathieu
23
- - "Jos\xC3\xA9 Valim"
17
+ - José Valim
24
18
  autorequire:
25
19
  bindir: bin
26
20
  cert_chain: []
27
-
28
- date: 2013-03-20 00:00:00 Z
21
+ date: 2013-07-19 00:00:00.000000000 Z
29
22
  dependencies: []
30
-
31
23
  description:
32
- email:
24
+ email:
33
25
  - josh@joshpeek.com
34
26
  - tarmo@itech.ee
35
27
  - jeremy@bitsweat.net
@@ -42,50 +34,40 @@ email:
42
34
  - 42@dmathieu.com
43
35
  - jose.valim@gmail.com
44
36
  executables: []
45
-
46
37
  extensions: []
47
-
48
- extra_rdoc_files:
38
+ extra_rdoc_files:
49
39
  - README.md
50
- files:
40
+ files:
51
41
  - README.md
42
+ - test/benchmark/memoist_benchmark.rb
52
43
  - test/memoist_test.rb
53
44
  - test/test_helper.rb
54
45
  - lib/memoist/core_ext/singleton_class.rb
55
46
  - lib/memoist.rb
56
47
  homepage: https://github.com/matthewrudy/memoist
57
- licenses: []
58
-
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
59
51
  post_install_message:
60
- rdoc_options:
52
+ rdoc_options:
61
53
  - --main
62
54
  - README.md
63
- require_paths:
55
+ require_paths:
64
56
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
83
67
  requirements: []
84
-
85
68
  rubyforge_project:
86
- rubygems_version: 1.8.24
69
+ rubygems_version: 2.0.3
87
70
  signing_key:
88
- specification_version: 3
71
+ specification_version: 4
89
72
  summary: memoize methods invocation
90
73
  test_files: []
91
-