🖥

#Ruby の配列 ( Array ) で差集合を得るのと、集合 ( Set ) で差集合を得るの、どちらが速度が出るのかほんの少しだけ試し

2019/07/06に公開

配列

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

https://github.com/YumaInaura/YumaInaura/issues/2252

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-07-06

Discussion