Created
January 30, 2012 10:05
-
-
Save dakatsuka/1703666 to your computer and use it in GitHub Desktop.
Redis incr benchmark / text vs hash
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
| 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 |
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
| $ 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