Skip to content

Instantly share code, notes, and snippets.

@yuki24
Created January 24, 2015 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuki24/52ec30f96fbea33268da to your computer and use it in GitHub Desktop.
Save yuki24/52ec30f96fbea33268da to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
Benchmark.ips do |x|
x.report "nothing" do
[1, 2, 3]
end
x.report "#-" do
[1, 2, 3] - [3]
end
x.report "#delete" do
[1, 2, 3].delete(3)
end
x.report "#delete + #tap" do
[1, 2, 3].tap{|ary| ary.delete(3) }
end
x.report "#delete + lvar" do
foo = [1, 2, 3]
foo.delete(3)
foo
end
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment