Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
fdf81b2d
Commit
fdf81b2d
authored
Mar 28, 2014
by
antirez
Browse files
hll-err.rb: speedup using pipelining.
parent
f2912336
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/hyperloglog/hll-err.rb
View file @
fdf81b2d
...
@@ -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
ele
=
Digest
::
SHA1
.
hexdigest
(
i
.
to_s
)
while
true
do
r
.
hlladd
(
'hll'
,
ele
)
100
.
times
{
if
i
!=
0
&&
(
i
%
10000
)
==
0
elements
=
[]
approx
=
r
.
hllcount
(
'hll'
)
1000
.
times
{
abs_err
=
(
approx
-
i
).
abs
ele
=
Digest
::
SHA1
.
hexdigest
(
i
.
to_s
)
rel_err
=
100
.
to_f
*
abs_err
/
i
elements
<<
ele
puts
"
#{
i
}
vs
#{
approx
}
:
#{
rel_err
}
%"
i
+=
1
end
}
}
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment