Commit fdf81b2d authored by antirez's avatar antirez
Browse files

hll-err.rb: speedup using pipelining.

parent f2912336
...@@ -9,13 +9,19 @@ require 'digest/sha1' ...@@ -9,13 +9,19 @@ require 'digest/sha1'
r = Redis.new r = Redis.new
r.del('hll') r.del('hll')
(1..1000000000).each{|i| i = 0
while true do
100.times {
elements = []
1000.times {
ele = Digest::SHA1.hexdigest(i.to_s) ele = Digest::SHA1.hexdigest(i.to_s)
r.hlladd('hll',ele) elements << ele
if i != 0 && (i%10000) == 0 i += 1
}
r.hlladd('hll',*elements)
}
approx = r.hllcount('hll') approx = r.hllcount('hll')
abs_err = (approx-i).abs abs_err = (approx-i).abs
rel_err = 100.to_f*abs_err/i rel_err = 100.to_f*abs_err/i
puts "#{i} vs #{approx}: #{rel_err}%" puts "#{i} vs #{approx}: #{rel_err}%"
end end
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment