⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (781 Bytes)
Feature #14994
ยป bench_enum_lazy_proc_chain.rb
chopraanmol1 (Anmol Chopra)
, 08/15/2018 06:35 AM
require
'benchmark'
grep_data
=
(
1
..
10
).
to_a
*
1000
uniq_data
=
(
1
..
10_000
).
to_a
N
=
100
def
b_loop
enum
i
=
0
while
i
<
N
i
+=
1
enum
.
each
{
|
x
|
x
*
1
}
end
end
Benchmark
.
bmbm
do
|
b
|
b
.
report
(
"Chained grep_v 20%"
){
b_loop
(
grep_data
.
lazy
.
grep_v
(
->
(
i
){
i
>
2
}).
grep_v
(
->
(
i
){
i
>
2
}))}
b
.
report
(
"Chained grep_v 50%"
){
b_loop
(
grep_data
.
lazy
.
grep_v
(
->
(
i
){
i
>
5
}).
grep_v
(
->
(
i
){
i
>
5
}))}
b
.
report
(
"Chained grep_v 100%"
){
b_loop
(
grep_data
.
lazy
.
grep_v
(
->
(
i
){
i
==
0
}).
grep_v
(
->
(
i
){
i
==
0
}))}
b
.
report
(
"Chained uniq 20%"
){
b_loop
(
uniq_data
.
lazy
.
uniq
{
|
i
|
i
%
2000
}.
uniq
{
|
i
|
i
%
2000
})}
b
.
report
(
"Chained uniq 50%"
){
b_loop
(
uniq_data
.
lazy
.
uniq
{
|
i
|
i
%
5000
}.
uniq
{
|
i
|
i
%
5000
})}
b
.
report
(
"Chained uniq 100%"
){
b_loop
(
uniq_data
.
lazy
.
uniq
{
|
i
|
i
%
10000
}.
uniq
{
|
i
|
i
%
10000
})}
end
(1-1/1)
Loading...