Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Ruby Benchmark example script
SUBMITTED BY:
Guest
DATE:
May 22, 2015, 12:03 p.m.
FORMAT:
Ruby
SIZE:
491 Bytes
Raw
Download
Tweet
HITS:
571
Go to comments
Report
require
'benchmark'
n
=
12352834
t
=
40000
Benchmark
.
bm
do
|
x
|
x
.
report
(
"Split map"
)
do
t
.
times
{
n
.
to_s
.
split
(
''
)
.
map
(
&
:to_i
)
}
end
x
.
report
(
"chars"
)
do
t
.
times
{
n
.
to_s
.
chars
.
map
(
&
:to_i
)
}
end
x
.
report
(
"each byte"
)
do
t
.
times
{
n
.
to_s
.
each_byte
.
map
{
|
x
|
x
-
48
}
}
end
x
.
report
(
"Numerical"
)
do
t
.
times
{
(
0
..
Math
.
log10
(
n
)
.
to_i
)
.
map
{
|
dp
|
n
/
10
**
dp
%
10
}
.
reverse
}
end
end
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus