From fdf81b2d3557ec379bb966db25ce14bfb5a988ff Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 28 Mar 2014 22:25:26 +0100 Subject: [PATCH] hll-err.rb: speedup using pipelining. --- utils/hyperloglog/hll-err.rb | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/utils/hyperloglog/hll-err.rb b/utils/hyperloglog/hll-err.rb index 96f9a68e..c40cfc7c 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