1# hll-err.rb - Copyright (C) 2014 Salvatore Sanfilippo 2# BSD license, See the COPYING file for more information. 3# 4# Check error of HyperLogLog Redis implementation for different set sizes. 5 6require 'rubygems' 7require 'redis' 8require 'digest/sha1' 9 10r = Redis.new 11r.del('hll') 12i = 0 13while true do 14 100.times { 15 elements = [] 16 1000.times { 17 ele = Digest::SHA1.hexdigest(i.to_s) 18 elements << ele 19 i += 1 20 } 21 r.pfadd('hll',elements) 22 } 23 approx = r.pfcount('hll') 24 abs_err = (approx-i).abs 25 rel_err = 100.to_f*abs_err/i 26 puts "#{i} vs #{approx}: #{rel_err}%" 27end 28