⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (605 Bytes)
Bug #11396
ยป hash_bench_3.rb
brunoe (Bruno Escherl)
, 07/26/2015 06:16 PM
require
'benchmark/ips'
collection_size
=
200000
sample_size
=
10000
values
=
(
1
..
collection_size
).
to_a
.
map
{
|
x
|
"THIS IS A LONGER STRING THAT IS ALSO UNIQUE
#{
x
}
"
}
symbol_hash
=
{}
string_hash
=
{}
values
.
each
do
|
x
|
symbol_hash
[
x
.
to_sym
]
=
1
string_hash
[
x
]
=
1
end
string_sample_array
=
values
.
sample
(
sample_size
)
symbol_sample_array
=
string_sample_array
.
map
(
&
:to_sym
)
Benchmark
.
ips
do
|
x
|
x
.
report
(
"string"
)
{
string_sample_array
.
each
do
|
s
|
string_hash
[
s
]
end
}
x
.
report
(
"symbol"
)
{
symbol_sample_array
.
each
do
|
s
|
symbol_hash
[
s
]
end
}
end
(1-1/1)
Loading...