2014-03-28 17:35:14 +00:00
|
|
|
# hll-err.rb - Copyright (C) 2014 Salvatore Sanfilippo
|
|
|
|
# BSD license, See the COPYING file for more information.
|
|
|
|
#
|
|
|
|
# Check error of HyperLogLog Redis implementation for different set sizes.
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'redis'
|
|
|
|
require 'digest/sha1'
|
|
|
|
|
|
|
|
r = Redis.new
|
|
|
|
r.del('hll')
|
2014-03-28 21:25:26 +00:00
|
|
|
i = 0
|
|
|
|
while true do
|
|
|
|
100.times {
|
|
|
|
elements = []
|
|
|
|
1000.times {
|
|
|
|
ele = Digest::SHA1.hexdigest(i.to_s)
|
|
|
|
elements << ele
|
|
|
|
i += 1
|
|
|
|
}
|
2018-03-16 15:34:04 +00:00
|
|
|
r.pfadd('hll',elements)
|
2014-03-28 21:25:26 +00:00
|
|
|
}
|
2014-03-31 20:48:01 +00:00
|
|
|
approx = r.pfcount('hll')
|
2014-03-28 21:25:26 +00:00
|
|
|
abs_err = (approx-i).abs
|
|
|
|
rel_err = 100.to_f*abs_err/i
|
|
|
|
puts "#{i} vs #{approx}: #{rel_err}%"
|
|
|
|
end
|