diff options
author | antirez <antirez@gmail.com> | 2014-03-28 22:25:26 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-03-28 22:25:30 +0100 |
commit | fdf81b2d3557ec379bb966db25ce14bfb5a988ff (patch) | |
tree | d5abc5d2757484f359fca605955a0c2676378b20 /utils | |
parent | f29123364b9f953c2467e52d8bf91c7cfd9a7f5d (diff) | |
download | redis-fdf81b2d3557ec379bb966db25ce14bfb5a988ff.tar.gz |
hll-err.rb: speedup using pipelining.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/hyperloglog/hll-err.rb | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/utils/hyperloglog/hll-err.rb b/utils/hyperloglog/hll-err.rb index 96f9a68ec..c40cfc7c3 100644 --- a/utils/hyperloglog/hll-err.rb +++ b/utils/hyperloglog/hll-err.rb @@ -9,13 +9,19 @@ require 'digest/sha1' r = Redis.new r.del('hll') -(1..1000000000).each{|i| - ele = Digest::SHA1.hexdigest(i.to_s) - r.hlladd('hll',ele) - if i != 0 && (i%10000) == 0 - approx = r.hllcount('hll') - abs_err = (approx-i).abs - rel_err = 100.to_f*abs_err/i - puts "#{i} vs #{approx}: #{rel_err}%" - end -} +i = 0 +while true do + 100.times { + elements = [] + 1000.times { + ele = Digest::SHA1.hexdigest(i.to_s) + elements << ele + i += 1 + } + r.hlladd('hll',*elements) + } + approx = r.hllcount('hll') + abs_err = (approx-i).abs + rel_err = 100.to_f*abs_err/i + puts "#{i} vs #{approx}: #{rel_err}%" +end |