Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aupajo/3dc3024813075a57f04c to your computer and use it in GitHub Desktop.
Save Aupajo/3dc3024813075a57f04c to your computer and use it in GitHub Desktop.
require 'redis'
require 'benchmark'
hash = {}
array = nil
redis = Redis.new
n_values = 720
redis.del redis.keys("demo:*")
Benchmark.bmbm do |x|
x.report("Setting #{n_values} hash keys") { n_values.times { |i| hash["demo:#{i}"] = 100 } }
x.report("Setting #{n_values} Redis keys") { n_values.times { |i| redis["demo:#{i}"] = 100 } }
x.report("Setting array with #{n_values} values") { array = [100] * (n_values - 1) }
x.report("Setting Redis list with #{n_values} items") { redis.lpush("demo:list", [100] * (n_values -1 )) }
x.report("Getting #{n_values} hash keys") { n_values.times { |i| hash["demo:#{i}"] } }
x.report("Getting array with #{n_values} values") { array }
x.report("Getting #{n_values} Redis keys") { n_values.times { |i| redis["demo:#{i}"] } }
x.report("Getting Redis list with #{n_values} items") { redis.lrange("demo:list", 0, n_values - 1) }
end
# Rehearsal ---------------------------------------------------------------------
# Setting 720 hash keys 0.000000 0.000000 0.000000 ( 0.001193)
# Setting 720 Redis keys 0.070000 0.030000 0.100000 ( 0.115302)
# Setting array with 720 values 0.000000 0.000000 0.000000 ( 0.000010)
# Setting Redis list with 720 items 0.000000 0.000000 0.000000 ( 0.001569)
# Getting 720 hash keys 0.000000 0.000000 0.000000 ( 0.000472)
# Getting array with 720 values 0.000000 0.000000 0.000000 ( 0.000004)
# Getting 720 Redis keys 0.080000 0.020000 0.100000 ( 0.109003)
# Getting Redis list with 720 items 0.000000 0.000000 0.000000 ( 0.004252)
# ------------------------------------------------------------ total: 0.200000sec
#
# user system total real
# Setting 720 hash keys 0.000000 0.000000 0.000000 ( 0.000516)
# Setting 720 Redis keys 0.050000 0.020000 0.070000 ( 0.088360)
# Setting array with 720 values 0.000000 0.000000 0.000000 ( 0.000018)
# Setting Redis list with 720 items 0.000000 0.000000 0.000000 ( 0.001383)
# Getting 720 hash keys 0.000000 0.000000 0.000000 ( 0.000414)
# Getting array with 720 values 0.000000 0.000000 0.000000 ( 0.000005)
# Getting 720 Redis keys 0.050000 0.020000 0.070000 ( 0.086625)
# Getting Redis list with 720 items 0.000000 0.000000 0.000000 ( 0.004241)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment