Created
March 23, 2011 16:54
-
-
Save jglass/883461 to your computer and use it in GitHub Desktop.
Benchmark of count vs. length in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'benchmark' | |
array = [] | |
1.upto(1000000) { |i| array << i } | |
Benchmark.bm(7) do |r| | |
r.report("Count:") { array.count } | |
r.report("Length:") { array.length } | |
end | |
# user system total real | |
# Count: 0.000000 0.000000 0.000000 ( 0.000010) | |
# Length: 0.000000 0.000000 0.000000 ( 0.000006) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment