File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env ruby
2
2
3
- require 'benchmark'
4
- require 'concurrent'
3
+ require 'benchmark/ips '
4
+ require 'concurrent/map '
5
5
6
- hash = { }
6
+ hash = { }
7
7
map = Concurrent ::Map . new
8
8
9
9
ENTRIES = 10_000
10
10
11
11
ENTRIES . times do |i |
12
- hash [ i ] = i
12
+ hash [ i ] = i
13
13
map [ i ] = i
14
14
end
15
15
16
- TESTS = 40_000_000
17
- Benchmark . bmbm do |results |
18
- key = rand ( 10_000 )
16
+ TESTS = 1_000
17
+ key = 2732 # srand(0) and rand(10_000)
19
18
19
+ Benchmark . ips do |results |
20
20
results . report ( 'Hash#[]' ) do
21
- TESTS . times { hash [ key ] }
21
+ hash [ key ]
22
22
end
23
23
24
24
results . report ( 'Map#[]' ) do
25
- TESTS . times { map [ key ] }
25
+ map [ key ]
26
26
end
27
27
28
28
results . report ( 'Hash#each_pair' ) do
29
- ( TESTS / ENTRIES ) . times { hash . each_pair { |k , v | v } }
29
+ hash . each_pair { |k , v | v }
30
30
end
31
31
32
32
results . report ( 'Map#each_pair' ) do
33
- ( TESTS / ENTRIES ) . times { map . each_pair { |k , v | v } }
33
+ map . each_pair { |k , v | v }
34
34
end
35
35
end
You can’t perform that action at this time.
0 commit comments