Created
August 1, 2019 20:56
-
-
Save gjcourt/826c2cd362e36670ab857ac04efbafb1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
$count = 5 | |
$item_count = 100_000 | |
$iterations = 1_000 | |
def setup | |
(1..$count).map{|x| {:num => x, :data => (1..$item_count).to_a}} | |
end | |
def test_one | |
seq = setup() | |
Benchmark.measure do | |
(1..$iterations).each do | |
res = seq.flat_map{|x| x[:data]} | |
raise Exception if res.length != $count * $item_count | |
end | |
end | |
end | |
def test_two | |
seq = setup() | |
Benchmark.measure do | |
(1..$iterations).each do | |
res = [] | |
seq.each{|x| res += x[:data]} | |
raise Exception if res.length != $count * $item_count | |
end | |
end | |
end | |
puts "Ran test one in #{test_one}s" | |
puts "Ran test two in #{test_two}s" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment