LoginSignup
0
0

More than 1 year has passed since last update.

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

Last updated at Posted at 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

チャットメンバー募集

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

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0