Last active
August 29, 2015 13:58
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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