Skip to content

Instantly share code, notes, and snippets.

@suryart
Created November 21, 2013 06:14
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 suryart/7576827 to your computer and use it in GitHub Desktop.
Save suryart/7576827 to your computer and use it in GitHub Desktop.
String .size vs .length
require 'benchmark'
string = 'dskjkd'
n = 500000
Benchmark.bm(40) do |x|
x.report("string.size "){ n.times { string.size } }
x.report("string.length "){ n.times { string.length } }
end
user system total real
string.size 0.040000 0.000000 0.040000 ( 0.039680)
string.length 0.040000 0.000000 0.040000 ( 0.038848)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment