-
-
Save Insood/daf2a783e25657ee5ad3038715568b4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
array = [] | |
1000000.times do | |
array << Random.rand | |
end | |
Benchmark.bm do |x| | |
x.report("Insert") do | |
h = {} | |
array.each do |a| | |
h[a] = true | |
end | |
end | |
x.report("Pass Array") do | |
a2 = array.map { |n| [n, true] } | |
h = Hash.new() | |
end | |
end | |
user system total real | |
Insert 0.240000 0.020000 0.260000 ( 0.235189) | |
Pass Array 0.140000 0.010000 0.150000 ( 0.135472) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment