Skip to content

Commit fa9c790

Browse files
committed
Modernize Concurrent::Map benchmark
1 parent eec01de commit fa9c790

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

examples/benchmark_map.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
#!/usr/bin/env ruby
22

3-
require 'benchmark'
4-
require 'concurrent'
3+
require 'benchmark/ips'
4+
require 'concurrent/map'
55

6-
hash = {}
6+
hash = {}
77
map = Concurrent::Map.new
88

99
ENTRIES = 10_000
1010

1111
ENTRIES.times do |i|
12-
hash[i] = i
12+
hash[i] = i
1313
map[i] = i
1414
end
1515

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)
1918

19+
Benchmark.ips do |results|
2020
results.report('Hash#[]') do
21-
TESTS.times { hash[key] }
21+
hash[key]
2222
end
2323

2424
results.report('Map#[]') do
25-
TESTS.times { map[key] }
25+
map[key]
2626
end
2727

2828
results.report('Hash#each_pair') do
29-
(TESTS / ENTRIES).times { hash.each_pair {|k,v| v} }
29+
hash.each_pair { |k,v| v }
3030
end
3131

3232
results.report('Map#each_pair') do
33-
(TESTS / ENTRIES).times { map.each_pair {|k,v| v} }
33+
map.each_pair { |k,v| v }
3434
end
3535
end

0 commit comments

Comments
 (0)