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 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 = { }
77map = Concurrent ::Map . new
88
99ENTRIES = 10_000
1010
1111ENTRIES . times do |i |
12- hash [ i ] = i
12+ hash [ i ] = i
1313 map [ i ] = i
1414end
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
3535end
You can’t perform that action at this time.
0 commit comments