diff options
author | antirez <antirez@gmail.com> | 2014-03-28 22:25:26 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-04-16 15:09:44 +0200 |
commit | 6aa1b2326934bf4522f3025777f6f8ab9e5323ad (patch) | |
tree | 9be7628a951c9a83e9ee4ba946b0925cb1f5d1a8 /utils | |
parent | a0b27c329a400d758d2842a58ca28b5689834bf3 (diff) | |
download | redis-6aa1b2326934bf4522f3025777f6f8ab9e5323ad.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 |