🖥
#Ruby の配列 ( Array ) で差集合を得るのと、集合 ( Set ) で差集合を得るの、どちらが速度が出るのかほんの少しだけ試し
配列
Benchmark.measure { 1000.times { [*1..10000] - [*5000..7000] } }
0.648272 0.086270 0.734542 ( 0.736078)
Benchmark.measure { 1000.times { [*1..10000] - [*5000..7000] } }
0.680731 0.100771 0.781502 ( 0.796209)
集合、遅いな。
Benchmark.measure { 1000.times { Set.new(1..10000).difference Set.new(5000..7000) } }
2.044662 0.281331 2.325993 ( 2.331730)
Benchmark.measure { 1000.times { Set.new(1..10000).difference Set.new(5000..7000) } }
2.025427 0.264227 2.289654 ( 2.295282)
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-07-06
Discussion