Created
October 28, 2012 10:35
-
-
Save kapso/3968277 to your computer and use it in GitHub Desktop.
Hiredis test
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
| extend ActiveSupport::Benchmarkable | |
| def logger; Rails.logger; end; | |
| def redis_connection(hire = true) | |
| hire ? Redis.new(logger: nil, driver: 'hiredis') : Redis.new(logger: nil) | |
| end | |
| def test_redis(size = 10_000, hire = true) | |
| key = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0, 24] | |
| data = {} | |
| size.times do |i| | |
| data[Digest::MD5.hexdigest((Time.now.to_i + i).to_s)[0, 24]] = rand(50) | |
| end | |
| redis = redis_connection(hire) | |
| benchmark("Driver hiredis(#{hire}) - Time taken to SAVE hash size(#{data.size})".bright.color(:blue), level: :info) do | |
| redis.mapped_hmset(key, data) | |
| end | |
| benchmark("Driver hiredis(#{hire}) - Time taken to FETCH hash size(#{data.size})".bright.color(:blue), level: :info) do | |
| (result = redis.hkeys(key)).present? | |
| end | |
| logger.info "\n" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment