Skip to content

Commit

Permalink
Modernize Concurrent::Map benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 27, 2023
1 parent eec01de commit fa9c790
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions examples/benchmark_map.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#!/usr/bin/env ruby

require 'benchmark'
require 'concurrent'
require 'benchmark/ips'
require 'concurrent/map'

hash = {}
hash = {}
map = Concurrent::Map.new

ENTRIES = 10_000

ENTRIES.times do |i|
hash[i] = i
hash[i] = i
map[i] = i
end

TESTS = 40_000_000
Benchmark.bmbm do |results|
key = rand(10_000)
TESTS = 1_000
key = 2732 # srand(0) and rand(10_000)

Benchmark.ips do |results|
results.report('Hash#[]') do
TESTS.times { hash[key] }
hash[key]
end

results.report('Map#[]') do
TESTS.times { map[key] }
map[key]
end

results.report('Hash#each_pair') do
(TESTS / ENTRIES).times { hash.each_pair {|k,v| v} }
hash.each_pair { |k,v| v }
end

results.report('Map#each_pair') do
(TESTS / ENTRIES).times { map.each_pair {|k,v| v} }
map.each_pair { |k,v| v }
end
end

0 comments on commit fa9c790

Please sign in to comment.