Skip to content

Instantly share code, notes, and snippets.

@yagince
Last active December 29, 2015 02:39
Show Gist options
  • Select an option

  • Save yagince/7602138 to your computer and use it in GitHub Desktop.

Select an option

Save yagince/7602138 to your computer and use it in GitHub Desktop.
KVS Benchmarks
require 'benchmark'
require "pp"
require 'libcdb'
require 'memcached'
require 'redis'
require 'hiredis'
require 'leveldb'
CDB_FILE = "test1.cdb"
LevelDB_FILE = "leveldb"
MEMD_SETTING = "localhost:11211"
REDIS_SETTING = {
host: :localhost,
port: 6379,
driver: :hiredis
}
i = 0
DATA = (1..100).inject({}){|acc, i| acc[i] = i.to_s * 5; acc; }.to_s
puts "DATA bytesize : #{ DATA.bytesize }"
memd = Memcached.new MEMD_SETTING
puts "== Wirte =============================================================="
Benchmark.bmbm do |x|
x.report("TinyCDB") {
LibCDB::CDB.open(CDB_FILE, "w") {|cdb|
(1..10000).each{|x| cdb[x.to_s] = DATA }
}
}
x.report("LevelDB") {
leveldb = LevelDB::DB.new LevelDB_FILE
(1..10000).each{|x| leveldb.put x.to_s, DATA }
}
x.report("memcached") {
memd = Memcached.new MEMD_SETTING
(1..10000).each{|x| memd.set(x.to_s, DATA) }
}
x.report("redis") {
redis = Redis.new REDIS_SETTING
(1..10000).each{|x| redis.set(x.to_s, DATA) }
}
end
puts "== Read =============================================================="
Benchmark.bmbm do |x|
x.report("TinyCDB") {
LibCDB::CDB.open(CDB_FILE) {|cdb|
(1..10000).each{|x| cdb[x.to_s] or raise }
}
}
x.report("LevelDB") {
leveldb = LevelDB::DB.new LevelDB_FILE
(1..10000).each{|x| leveldb.get x.to_s }
}
x.report("memcached") {
memd = Memcached.new MEMD_SETTING
(1..10000).each{|x| memd.get(x.to_s) or raise }
}
x.report("redis") {
redis = Redis.new REDIS_SETTING
(1..10000).each{|x| redis.get(x.to_s) or raise }
}
end
DATA bytesize : 23358
== Wirte ==============================================================
Rehearsal ---------------------------------------------
TinyCDB 0.030000 0.200000 0.230000 ( 0.565926)
LevelDB 2.500000 2.590000 5.090000 ( 15.034853)
memcached 0.350000 0.200000 0.550000 ( 0.946619)
redis 0.240000 0.180000 0.420000 ( 0.806655)
------------------------------------ total: 6.290000sec
user system total real
TinyCDB 0.030000 0.200000 0.230000 ( 0.543706)
LevelDB 3.290000 3.750000 7.040000 ( 23.765673)
memcached 0.340000 0.190000 0.530000 ( 0.900448)
redis 0.230000 0.180000 0.410000 ( 0.804622)
== Read ==============================================================
Rehearsal ---------------------------------------------
TinyCDB 0.190000 0.070000 0.260000 ( 0.265296)
LevelDB 1.490000 1.250000 2.740000 ( 6.001690)
memcached 0.290000 0.210000 0.500000 ( 0.771998)
redis 0.410000 0.270000 0.680000 ( 0.932830)
------------------------------------ total: 4.180000sec
user system total real
TinyCDB 0.190000 0.050000 0.240000 ( 0.241227)
LevelDB 0.800000 0.440000 1.240000 ( 2.887865)
memcached 0.290000 0.190000 0.480000 ( 0.747268)
redis 0.410000 0.280000 0.690000 ( 0.929578)
DATA bytesize : 1752
== Wirte ==============================================================
Rehearsal ---------------------------------------------
TinyCDB 0.010000 0.050000 0.060000 ( 0.057837)
LevelDB 0.120000 0.030000 0.150000 ( 0.148532)
memcached 0.160000 0.160000 0.320000 ( 0.614953)
redis 0.220000 0.160000 0.380000 ( 0.708149)
------------------------------------ total: 0.910000sec
user system total real
TinyCDB 0.010000 0.030000 0.040000 ( 0.034997)
LevelDB 0.170000 0.070000 0.240000 ( 0.324532)
memcached 0.140000 0.160000 0.300000 ( 0.602615)
redis 0.210000 0.160000 0.370000 ( 0.658110)
== Read ==============================================================
Rehearsal ---------------------------------------------
TinyCDB 0.030000 0.010000 0.040000 ( 0.032672)
LevelDB 0.440000 0.120000 0.560000 ( 0.765023)
memcached 0.130000 0.160000 0.290000 ( 0.545114)
redis 0.210000 0.150000 0.360000 ( 0.614752)
------------------------------------ total: 1.250000sec
user system total real
TinyCDB 0.020000 0.010000 0.030000 ( 0.024875)
LevelDB 0.290000 0.020000 0.310000 ( 0.338106)
memcached 0.130000 0.150000 0.280000 ( 0.533313)
redis 0.230000 0.170000 0.400000 ( 0.666459)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment