lru_redux 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5db2f5b8b5846daedc0bb154d16890dce33de740
4
- data.tar.gz: 054c9c30e079882048d96316d01287dc9fea4ed0
3
+ metadata.gz: 5cc0a735826e07e6de5cc53e431c4fd87ff32413
4
+ data.tar.gz: 28446a234e46a8b91a57e56b1677b2d4b16ac68f
5
5
  SHA512:
6
- metadata.gz: 158d6276f7699180a9d1044ea68d8c36c5627c916ed28d39809ae661b8c117382cf6d0dbb2a0d9939bbc769bc5e654fa6c0f35d11d04f8942c5355a5ae0dff47
7
- data.tar.gz: b718d96261b1bc002dd2d684f7f600c946e087d75598b629b5802528ed564502d04c94b5a5a39c8c9ca47869a5b9b59b245d7b5bbbed74616aef6cb8692f7fdd
6
+ metadata.gz: bc3d02a4d7b2f4f3db8189e1e4c5c1515c2e3c713d58ce2e84ba46296aec74312400c11e60f31cebfc8fd757210c347c5beb0ea13375501164a847a12326bebb
7
+ data.tar.gz: 4c46517993f671162baa8aa946ad201d8ce00f662b1b61f8583463041752f73da2ee57ff802e130448ae427cc12064a32eb4d4e815d3ed96e941e7d2db69593b
data/README.md CHANGED
@@ -66,21 +66,21 @@ cache = LruRedux::ThreadSafeCache.new(100)
66
66
  see: benchmark directory (a million random lookup / store)
67
67
 
68
68
  ```
69
- sam@ubuntu:~/Source/lru_redux/bench$ ruby ./bench.rb
69
+ $ ruby ./bench/bench.rb
70
70
  Rehearsal ---------------------------------------------------------
71
- thread safe lru 27.940000 0.020000 27.960000 ( 28.026869)
72
- lru gem 2.250000 0.010000 2.260000 ( 2.256652)
73
- lru_cache gem 1.980000 0.000000 1.980000 ( 1.979244)
74
- lru_redux gem 1.190000 0.000000 1.190000 ( 1.187640)
75
- lru_redux thread safe 2.480000 0.000000 2.480000 ( 2.486314)
76
- ----------------------------------------------- total: 35.870000sec
71
+ thread safe lru 4.530000 0.020000 4.550000 ( 4.540861)
72
+ lru gem 2.040000 0.000000 2.040000 ( 2.046777)
73
+ lru_cache gem 1.660000 0.010000 1.670000 ( 1.670404)
74
+ lru_redux gem 1.200000 0.000000 1.200000 ( 1.197036)
75
+ lru_redux thread safe 2.520000 0.000000 2.520000 ( 2.526945)
76
+ ----------------------------------------------- total: 11.980000sec
77
77
 
78
78
  user system total real
79
- thread safe lru 28.010000 0.000000 28.010000 ( 28.023534)
80
- lru gem 2.250000 0.000000 2.250000 ( 2.256425)
81
- lru_cache gem 1.920000 0.000000 1.920000 ( 1.925362)
82
- lru_redux gem 1.170000 0.000000 1.170000 ( 1.170970)
83
- lru_redux thread safe 2.480000 0.000000 2.480000 ( 2.488169)
79
+ thread safe lru 4.550000 0.030000 4.580000 ( 4.581848)
80
+ lru gem 2.060000 0.000000 2.060000 ( 2.056636)
81
+ lru_cache gem 1.660000 0.010000 1.670000 ( 1.669312)
82
+ lru_redux gem 1.180000 0.000000 1.180000 ( 1.187639)
83
+ lru_redux thread safe 2.530000 0.000000 2.530000 ( 2.532061)
84
84
 
85
85
  ```
86
86
 
@@ -95,6 +95,10 @@ lru_redux thread safe 2.480000 0.000000 2.480000 ( 2.488169)
95
95
 
96
96
  ## Changlog
97
97
 
98
+ ###version 0.8.3 - 20-Feb-2014
99
+
100
+ - Perf: improve ThreadSafeCache performance @Sevrius
101
+
98
102
  ###version 0.8.2 - 16-Feb-2014
99
103
 
100
104
  - Perf: use #size instead of #count when checking length @Sebrius
@@ -1,8 +1,8 @@
1
- require "rubygems"
2
- require "lru"
3
- require "benchmark"
4
- require "lru_cache"
5
- require "threadsafe-lru"
1
+ require 'rubygems'
2
+ require 'lru'
3
+ require 'benchmark'
4
+ require 'lru_cache'
5
+ require 'threadsafe-lru'
6
6
  $LOAD_PATH.unshift File.expand_path '../lib'
7
7
  require File.expand_path('../../lib/lru_redux', __FILE__)
8
8
 
@@ -24,8 +24,6 @@ bm = Benchmark.bmbm do |bm|
24
24
  [
25
25
  [lru, "lru gem"],
26
26
  [lru_cache, "lru_cache gem"],
27
- [lru_redux, "lru_redux gem"],
28
- [lru_redux_thread_safe, "lru_redux thread safe"]
29
27
  ].each do |cache, name|
30
28
  bm.report name do
31
29
  1_000_000.times do
@@ -33,4 +31,15 @@ bm = Benchmark.bmbm do |bm|
33
31
  end
34
32
  end
35
33
  end
34
+
35
+ [
36
+ [lru_redux, "lru_redux gem"],
37
+ [lru_redux_thread_safe, "lru_redux thread safe"]
38
+ ].each do |cache, name|
39
+ bm.report name do
40
+ 1_000_000.times do
41
+ cache.getset(rand(2_000)) { :value }
42
+ end
43
+ end
44
+ end
36
45
  end
@@ -1,22 +1,75 @@
1
- require 'thread'
2
1
  require 'monitor'
3
2
 
4
3
  class LruRedux::ThreadSafeCache < LruRedux::Cache
5
4
  include MonitorMixin
6
- def initialize(size)
7
- super(size)
5
+
6
+ def initialize(max_size)
7
+ super(max_size)
8
+ end
9
+
10
+ def max_size=(size)
11
+ synchronize do
12
+ super(size)
13
+ end
8
14
  end
9
15
 
10
- def self.synchronize(*methods)
11
- methods.each do |method|
12
- define_method method do |*args, &blk|
13
- synchronize do
14
- super(*args,&blk)
15
- end
16
- end
16
+ def getset(key)
17
+ synchronize do
18
+ super(key)
17
19
  end
18
20
  end
19
21
 
20
- synchronize :[], :[]=, :each, :to_a, :delete, :count, :valid?, :max_size, :fetch, :getset
22
+ def fetch(key)
23
+ synchronize do
24
+ super(key)
25
+ end
26
+ end
27
+
28
+ def [](key)
29
+ synchronize do
30
+ super(key)
31
+ end
32
+ end
33
+
34
+ def []=(key, value)
35
+ synchronize do
36
+ super(key, value)
37
+ end
38
+ end
39
+
40
+ def each
41
+ synchronize do
42
+ super
43
+ end
44
+ end
21
45
 
46
+ def to_a
47
+ synchronize do
48
+ super
49
+ end
50
+ end
51
+
52
+ def delete(key)
53
+ synchronize do
54
+ super(key)
55
+ end
56
+ end
57
+
58
+ def clear
59
+ synchronize do
60
+ super
61
+ end
62
+ end
63
+
64
+ def count
65
+ synchronize do
66
+ super
67
+ end
68
+ end
69
+
70
+ def valid?
71
+ synchronize do
72
+ super
73
+ end
74
+ end
22
75
  end
@@ -1,3 +1,3 @@
1
1
  module LruRedux
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lru_redux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler