memoist2 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/LICENCE +20 -0
- data/README.md +35 -1
- data/Rakefile +2 -1
- data/benchmark.rb +72 -0
- data/memoist2.gemspec +3 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829d1ae3d37827ff9822e3435752208f5d96c376
|
4
|
+
data.tar.gz: 399d3e864904a801173ac73416e9fac4f86dad09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 437e09101708635c4861064ed156cd5d6a419468f4da942395deb7c90b0c19569dd04515c6ad635d6d41a1c620a72084175b4b277e0c1ca3517baf23e8614f50
|
7
|
+
data.tar.gz: e84bae0e10a00897fe7afb5eabfa81b9d2d88294664896f0c7b5df1655fa0d514f5dbb9d2b5062dcb239e72fed40e48a23e6c1c4badc9574c9f53987a3da68ae
|
data/Gemfile
CHANGED
data/LICENCE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Matthew Rudy Jacobs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,4 +1,38 @@
|
|
1
1
|
memoist2
|
2
2
|
========
|
3
3
|
|
4
|
-
Simple Memoization for Ruby 2.0
|
4
|
+
Simple Memoization for Ruby 2.0
|
5
|
+
|
6
|
+
Example
|
7
|
+
=======
|
8
|
+
|
9
|
+
Memoize an instance method
|
10
|
+
|
11
|
+
class Foo
|
12
|
+
extend Memoist2
|
13
|
+
|
14
|
+
def bar
|
15
|
+
sleep 1 && 2**10
|
16
|
+
end
|
17
|
+
memoize :bar
|
18
|
+
end
|
19
|
+
|
20
|
+
Memoize a class method
|
21
|
+
|
22
|
+
class Foo
|
23
|
+
class << self
|
24
|
+
extend Memoist2
|
25
|
+
|
26
|
+
def bar
|
27
|
+
# something expensive
|
28
|
+
end
|
29
|
+
memoize :bar
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Licence
|
34
|
+
=======
|
35
|
+
|
36
|
+
Licensed under the MIT licence.
|
37
|
+
|
38
|
+
See the file LICENCE.
|
data/Rakefile
CHANGED
@@ -15,11 +15,12 @@ spec = Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
# Basic details
|
17
17
|
s.name = "memoist2"
|
18
|
-
s.version = "0.1.
|
18
|
+
s.version = "0.1.2"
|
19
19
|
s.summary = "Really simple memoization for ruby 2.0"
|
20
20
|
s.author = "Matthew Rudy Jacobs"
|
21
21
|
s.email = "MatthewRudyJacobs@gmail.com"
|
22
22
|
s.homepage = "https://github.com/matthewrudy/memoist2"
|
23
|
+
s.license = "MIT"
|
23
24
|
|
24
25
|
s.has_rdoc = true
|
25
26
|
s.extra_rdoc_files = %w(README.md)
|
data/benchmark.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
<<-INTRO
|
2
|
+
|
3
|
+
Question:
|
4
|
+
Is Memoist2 performant?
|
5
|
+
|
6
|
+
Answer:
|
7
|
+
|
8
|
+
Raw is a little bit slower
|
9
|
+
user system total real
|
10
|
+
raw method 2.220000 0.000000 2.220000 ( 2.216027)
|
11
|
+
memoist2 method 1.670000 0.000000 1.670000 ( 1.670678)
|
12
|
+
manual memoized (||=) 1.280000 0.000000 1.280000 ( 1.286099)
|
13
|
+
manual memoized (defined?) 1.380000 0.000000 1.380000 ( 1.372037)
|
14
|
+
|
15
|
+
INTRO
|
16
|
+
|
17
|
+
require 'benchmark'
|
18
|
+
require 'memoist2'
|
19
|
+
|
20
|
+
TIMES = 10_000_000
|
21
|
+
|
22
|
+
class MyClass
|
23
|
+
extend Memoist2
|
24
|
+
|
25
|
+
def raw
|
26
|
+
(2**10)**2 # something mildly difficult
|
27
|
+
end
|
28
|
+
|
29
|
+
def memoized
|
30
|
+
1
|
31
|
+
end
|
32
|
+
memoize :memoized
|
33
|
+
|
34
|
+
def variable_cache
|
35
|
+
@variable_cache ||= 1
|
36
|
+
end
|
37
|
+
|
38
|
+
def defined_cache
|
39
|
+
unless defined?(@defined_cache)
|
40
|
+
@defined_cache = 1
|
41
|
+
end
|
42
|
+
@defined_cache
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
INSTANCE = MyClass.new
|
47
|
+
|
48
|
+
Benchmark.bm(30) do |x|
|
49
|
+
x.report("raw method") do
|
50
|
+
TIMES.times do
|
51
|
+
INSTANCE.raw
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
x.report("memoist2 method") do
|
56
|
+
TIMES.times do
|
57
|
+
INSTANCE.memoized
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
x.report("manual memoized (||=)") do
|
62
|
+
TIMES.times do
|
63
|
+
INSTANCE.variable_cache
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
x.report("manual memoized (defined?)") do
|
68
|
+
TIMES.times do
|
69
|
+
INSTANCE.defined_cache
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/memoist2.gemspec
CHANGED
@@ -2,17 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "memoist2"
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Matthew Rudy Jacobs"]
|
9
9
|
s.date = "2013-07-19"
|
10
10
|
s.email = "MatthewRudyJacobs@gmail.com"
|
11
11
|
s.extra_rdoc_files = ["README.md"]
|
12
|
-
s.files = [".gitignore", ".rspec", ".ruby-version", ".travis.yml", "Gemfile", "README.md", "Rakefile", "example/foo.rb", "lib/memoist2.rb", "spec/memoist2_spec.rb", "spec/spec_helper.rb"]
|
12
|
+
s.files = [".gitignore", ".rspec", ".ruby-version", ".travis.yml", "Gemfile", "README.md", "Rakefile", "example/foo.rb", "lib/memoist2.rb", "memoist2.gemspec", "spec/memoist2_spec.rb", "spec/spec_helper.rb"]
|
13
13
|
s.homepage = "https://github.com/matthewrudy/memoist2"
|
14
14
|
s.rdoc_options = ["--main", "README.md"]
|
15
15
|
s.require_paths = ["lib"]
|
16
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.0.0")
|
16
17
|
s.rubygems_version = "2.0.3"
|
17
18
|
s.summary = "Really simple memoization for ruby 2.0"
|
18
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memoist2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Rudy Jacobs
|
@@ -50,15 +50,18 @@ files:
|
|
50
50
|
- .ruby-version
|
51
51
|
- .travis.yml
|
52
52
|
- Gemfile
|
53
|
+
- LICENCE
|
53
54
|
- README.md
|
54
55
|
- Rakefile
|
56
|
+
- benchmark.rb
|
55
57
|
- example/foo.rb
|
56
58
|
- lib/memoist2.rb
|
57
59
|
- memoist2.gemspec
|
58
60
|
- spec/memoist2_spec.rb
|
59
61
|
- spec/spec_helper.rb
|
60
62
|
homepage: https://github.com/matthewrudy/memoist2
|
61
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- MIT
|
62
65
|
metadata: {}
|
63
66
|
post_install_message:
|
64
67
|
rdoc_options:
|