Created
September 6, 2014 14:00
-
-
Save murajun1978/9642a11c1bb536b2d500 to your computer and use it in GitHub Desktop.
Arrayのベンチマーク
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' | |
require 'set' | |
array = Array.new(1_000_000){[1, 2, 3]} | |
set = array.to_set | |
Benchmark.bm(15) do |x| | |
x.report('array:') { array.each do |n| n.include?(3) end } | |
x.report('set:') { set.each do |n| n.include?(3) end } | |
end | |
# 実行結果 | |
user system total real | |
array: 0.200000 0.000000 0.200000 ( 0.203315) | |
set: 0.000000 0.000000 0.000000 ( 0.000010) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考になりました !!
こうなると to_set のコストも知っておきたい所ですね。