summaryrefslogtreecommitdiff
path: root/utils/hyperloglog
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-03-28 22:25:26 +0100
committerantirez <antirez@gmail.com>2014-03-28 22:25:30 +0100
commitfdf81b2d3557ec379bb966db25ce14bfb5a988ff (patch)
treed5abc5d2757484f359fca605955a0c2676378b20 /utils/hyperloglog
parentf29123364b9f953c2467e52d8bf91c7cfd9a7f5d (diff)
downloadredis-fdf81b2d3557ec379bb966db25ce14bfb5a988ff.tar.gz
hll-err.rb: speedup using pipelining.
Diffstat (limited to 'utils/hyperloglog')
-rw-r--r--utils/hyperloglog/hll-err.rb26
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