Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
Created January 30, 2012 10:05
Show Gist options
  • Save dakatsuka/1703666 to your computer and use it in GitHub Desktop.
Save dakatsuka/1703666 to your computer and use it in GitHub Desktop.
Redis incr benchmark / text vs hash
require "benchmark"
require "redis"
redis = Redis.new(host: '127.0.0.1', port: 6379)
Benchmark.bm(10) do |x|
x.report("text type:") {
50000.times do |i|
redis.set "key#{i}", 0
redis.incr "key#{i}"
redis.decr "key#{i}"
end
print redis.info["used_memory_human"]
redis.flushdb
}
x.report("hash type:") {
50000.times do |i|
redis.hset "key", i, 0
redis.hincrby "key", i, 1
redis.hincrby "key", i, -1
end
print redis.info["used_memory_human"]
redis.flushdb
}
end
$ ruby benchmark.rb
user system total real
text type: 4.43M 4.170000 2.570000 6.740000 ( 12.598659)
hash type: 3.53M 5.000000 2.870000 7.870000 ( 14.536784)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment