Skip to content

Instantly share code, notes, and snippets.

@nofxx
Created June 18, 2009 20:02
Show Gist options
  • Save nofxx/132160 to your computer and use it in GitHub Desktop.
Save nofxx/132160 to your computer and use it in GitHub Desktop.
Tokyo Cabinet / Memcached
require 'memcache'
require 'memcached'
require 'rufus/tokyo'
require 'tokyocabinet'
tc = TokyoCabinet::HDB.new('tc.tch')
tffi = Rufus::Tokyo::Cabinet.new('tffi.tch')
mc = Memcached.new "localhost:11211"
mr = MemCache.new "localhost:11211"
Benchmark.bmbm do |b|
b.report { 1000000.times { |i| tc.put i.to_s, "x" } }
b.report { 1000000.times { |i| tffi[i.to_s] = "x" } }
b.report { 1000000.times { |i| mc.set i.to_s, "x" } }
b.report { 1000000.times { |i| mr.set i.to_s, "x" } }
end
Results:
Linux 2.6.30-ARCH i686 Intel(R) Core(TM)2 Duo CPU E8500 @ 3.16GHz
Rehearsal ------------------------------------
TokyoC 1.030000 0.200000 1.230000 ( 1.232751)
TokyoF 4.020000 0.370000 4.390000 ( 4.431397)
MemC 8.640000 7.920000 16.560000 ( 25.574098)
MemPR 63.730000 12.670000 76.400000 ( 88.456076)
user system total real
TokyoC 1.110000 0.130000 1.240000 ( 1.251074)
TokyoF 4.060000 0.350000 4.410000 ( 4.454559)
MemC 9.260000 7.810000 17.070000 ( 27.245979)
MemPR 63.330000 12.860000 76.190000 ( 88.369831)
.......................................................
Tokyo Cabinet 1.4.27
Memcached 1.2.8 (libmemcached 0.30)
TokyoC -> Tokyo Cabinet C bindings (1.26)
TokyoF -> Rufus FFI Adapter (0.1.13)
MemPR -> Memcached pure ruby (memcache-client 1.7.4)
MemC -> Memcached C bindings (memcached 0.15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment