Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@seban
Created November 28, 2011 08:21
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 seban/1399594 to your computer and use it in GitHub Desktop.
Save seban/1399594 to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bm(7) do |x|
x.report("length") { 10.times { Array.new(10_000, 1).length > 0 } }
x.report("any?") { 10.times { Array.new(10_000, 1).any? } }
end
array = Array.new(10_000, 1)
Benchmark.bm(7) do |x|
x.report("length") { 100.times { array.length > 0 } }
x.report("any?") { 100.times { array.any? } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment