Permalink
Browse files

more benchmark..

  • Loading branch information...
nofxx committed Jul 1, 2009
1 parent 6b2ca03 commit c8fbb5a69558840b25ecf2d7a14fc08a962a8e1e
Showing with 39 additions and 16 deletions.
  1. +33 −11 benchmark/tokyo_store.rb
  2. +6 −5 lib/tokyo_store.rb
View
@@ -1,4 +1,7 @@
#
+# Tokyo Store
+#
+# Benchmark vs MemCacheStore on memcached and tyrant
#
require 'rubygems'
require 'active_support'
@@ -7,28 +10,47 @@
require 'tokyo_store'
#include TokyoCabinet
+P = "x" * 100
+M = P * 10
+G = M * 10
+OBJ = { :small => P, :medium => M, :big => G}
+
@tokyo = ActiveSupport::Cache.lookup_store :tokyo_store, "localhost"
@memca = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost:11211"
@memto = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost:45001"
-# # # Read & Write
+# # Read & Write
Benchmark.bmbm do |b|
- b.report("TokyoStore#w") { 10_000.times { |i| @tokyo.write i.to_s, "x" }}
- b.report("TokyoStore#r") { 10_000.times { |i| @tokyo.read i.to_s }}
- b.report("MemCache#w") { 10_000.times { |i| @memca.write i.to_s, "x" }}
- b.report("MemCache#r") { 10_000.times { |i| @memca.read i.to_s }}
- b.report("MemCacheTo#w") { 10_000.times { |i| @memto.write i.to_s, "x" }}
- b.report("MemCacheTo#r") { 10_000.times { |i| @memto.read i.to_s }}
+ b.report("TokyoStore#P") { 10_000.times { |i| @tokyo.write i.to_s, P }}
+ b.report("MemCacheD#P") { 10_000.times { |i| @memca.write i.to_s, P }}
+ b.report("MemCacheT#P") { 10_000.times { |i| @memto.write i.to_s, P }}
+
+ b.report("TokyoStore#M") { 10_000.times { |i| @tokyo.write i.to_s, M }}
+ b.report("MemCacheD#M") { 10_000.times { |i| @memca.write i.to_s, M }}
+ b.report("MemCacheT#M") { 10_000.times { |i| @memto.write i.to_s, M }}
+
+ b.report("TokyoStore#G") { 10_000.times { |i| @tokyo.write i.to_s, G }}
+ b.report("MemCacheD#G") { 10_000.times { |i| @memca.write i.to_s, G }}
+ b.report("MemCacheT#G") { 10_000.times { |i| @memto.write i.to_s, G }}
+
+ b.report("TokyoStore#OB") { 10_000.times { |i| @tokyo.write i.to_s, OBJ }}
+ b.report("MemCacheD#OB") { 10_000.times { |i| @memca.write i.to_s, OBJ }}
+ b.report("MemCacheT#OB") { 10_000.times { |i| @memto.write i.to_s, OBJ }}
+
+ b.report("TokyoStore#R") { 10_000.times { |i| @tokyo.read i.to_s }}
+ b.report("MemCacheD#R") { 10_000.times { |i| @memca.read i.to_s }}
+ b.report("MemCacheT#R") { 10_000.times { |i| @memto.read i.to_s }}
+
end
puts
# # Read & Write
Benchmark.bmbm do |b|
- b.report("Tokyo#w") { 100.times { |j| Thread.new { 100.times { |i| @tokyo.write "#{j}-#{i}", "x" }}}}
- b.report("Tokyo#r") { 100.times { |j| Thread.new { 100.times { |i| @tokyo.read "#{j}-#{i}" }}}}
- b.report("MemCa#w") { 100.times { |j| Thread.new { 100.times { |i| @memca.write "#{j}-#{i}", "x" }}}}
+ b.report("MemCa#w") { 100.times { |j| Thread.new { 100.times { |i| @memca.write "#{j}-#{i}", OBJ }}}}
b.report("Memca#r") { 100.times { |j| Thread.new { 100.times { |i| @memca.read "#{j}-#{i}" }}}}
- b.report("Memto#w") { 100.times { |j| Thread.new { 100.times { |i| @memto.write "#{j}-#{i}", "x" }}}}
+ b.report("Memto#w") { 100.times { |j| Thread.new { 100.times { |i| @memto.write "#{j}-#{i}", OBJ }}}}
b.report("Memto#r") { 100.times { |j| Thread.new { 100.times { |i| @memto.read "#{j}-#{i}" }}}}
+ b.report("Tokyo#w") { 100.times { |j| Thread.new { 100.times { |i| @tokyo.write "#{j}-#{i}", OBJ }}}}
+ b.report("Tokyo#r") { 100.times { |j| Thread.new { 100.times { |i| @tokyo.read "#{j}-#{i}" }}}}
end
View
@@ -50,7 +50,7 @@ def read_multi(*keys)
def read(key, options = nil) # :nodoc:
super
- @data[key]
+ Marshal.load(@data[key])
# if str = @data.get(key)
# Marshal.load str
# else
@@ -93,13 +93,14 @@ def exist?(key, options = nil) # :nodoc:
end
def increment(key, amount = 1) # :nodoc:
- log("incrementing", key, amount)
- # TODO
+ write(key, read(key) + amount)
+ # TODO native?
end
def decrement(key, amount = 1) # :nodoc:
- log("decrement", key, amount)
- #TODO
+ write(key, read(key) - amount)
+ # log("decrement", key, amount)
+ #TODO native?
end
def delete_matched(matcher, options = nil) # :nodoc:

0 comments on commit c8fbb5a

Please sign in to comment.