Skip to content

Instantly share code, notes, and snippets.

@asterite
Created January 16, 2016 01:14
Show Gist options
  • Save asterite/8bdc0e46426d71d41fdc to your computer and use it in GitHub Desktop.
Save asterite/8bdc0e46426d71d41fdc to your computer and use it in GitHub Desktop.
require "benchmark/ips"
CONSTANT = %w(foo bar baz)
Benchmark.ips do |x|
x.report("literal") { %w(foo bar baz).include?("foo") }
x.report("constant") { CONSTANT.include?("foo") }
end
Calculating -------------------------------------
literal 81.923k i/100ms
constant 111.304k i/100ms
-------------------------------------------------
literal 2.104M (± 4.1%) i/s - 10.568M
constant 4.386M (± 4.5%) i/s - 21.927M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment