Skip to content

Instantly share code, notes, and snippets.

@matsumotory
Last active August 29, 2015 13:58
Show Gist options
  • Save matsumotory/9954779 to your computer and use it in GitHub Desktop.
Save matsumotory/9954779 to your computer and use it in GitHub Desktop.
mruby-redis vs mruby-vedis vs mruby-memcached vs Hash refs: http://blog.matsumoto-r.jp/?p=4071
class SimpleBenchmark
def initialize width = 0
@width = width
end
def measure label
start = Time.now
yield if block_given?
passed = Time.now - start
puts "#{make_fixed_label(label)}passed time #{passed} sec"
end
def make_fixed_label label
if @width - label.length > 0
label + ' ' * (@width - label.length)
else
label
end
end
end
benchmark = SimpleBenchmark.new 12
r = Redis.new "127.0.0.1", 6379
v = Vedis.new
d = Vedis.new "/tmp/vedis.db"
m = Memcached.new "127.0.0.1:11211"
h = Hash.new
n = 100000
[r, v, d, m, h].each do |kvs|
benchmark.measure("#{kvs.class}: ") do
n.times do |t|
kvs[t.to_s] = t.to_s
if kvs[t.to_s] != t.to_s
raise "#{kvs.class}: set/get #{t.to_s} failed"
end
end
end
end
r.close
v.close
d.close
m.close
MRuby::Build.new do |conf|
# load specific toolchain settings
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.gem :github => 'matsumoto-r/mruby-redis'
conf.gem :github => 'matsumoto-r/mruby-vedis'
conf.gem :github => 'matsumoto-r/mruby-memcached'
conf.gembox 'default'
end
$ ./bin/mruby bench.rb
Redis: passed time 5.37813999999999 sec
Vedis: passed time 0.16775399999999 sec
Vedis: passed time 0.30398399999999 sec
Memcached: passed time 3.43488299999999 sec
Hash: passed time 2.25670599999999 sec
$ ./bin/mruby bench.rb
Redis: passed time 5.1858560 sec
Vedis: passed time 0.15705299999999 sec
Vedis: passed time 0.58392599999999 sec
Memcached: passed time 3.35226299999999 sec
Hash: passed time 0.52785199999999 sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment