Skip to content

Instantly share code, notes, and snippets.

@oieioi
Created August 6, 2021 09:21
Show Gist options
  • Select an option

  • Save oieioi/1b9564ba314b56e24f6a1d311e29c243 to your computer and use it in GitHub Desktop.

Select an option

Save oieioi/1b9564ba314b56e24f6a1d311e29c243 to your computer and use it in GitHub Desktop.
require 'benchmark'
time = 100_000_0
ary = [1,1,1,1,1,1,1,1,1,1,2,2,2,1,2,2,2,1,2,2,2,2,1,2,1]
puts "Array#uniq:#{Benchmark.realtime { time.times { ary.uniq } }}"
puts "Array#| :#{Benchmark.realtime { time.times { ary | [] } }}"
@oieioi

oieioi commented Aug 6, 2021

Copy link
Copy Markdown
Author

uniq の方がほんのちょっとだけ早い。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment