Skip to content

Instantly share code, notes, and snippets.

@codatory
Created December 11, 2013 16:07
Show Gist options
  • Save codatory/7913193 to your computer and use it in GitHub Desktop.
Save codatory/7913193 to your computer and use it in GitHub Desktop.
String Performance
# Load benchmark from stdlib
require 'benchmark'
# Pre-compute 10 million integers, return nothing to stdout in IRB
a = (0..9999999).to_a; nil
# Run the test 10x to isolate any fluctuation
(0..9).each do
Benchmark.bm do |x|
x.report("Double Quotes") { a.each {"This is a string"} }
x.report('Single Quotes') { a.each {'This is a string'} }
end
end
user system total real
Double Quotes 17.790000 0.000000 17.790000 ( 17.790273)
Single Quotes 17.820000 0.000000 17.820000 ( 17.815516)
user system total real
Double Quotes 17.800000 0.000000 17.800000 ( 17.798947)
Single Quotes 17.840000 0.000000 17.840000 ( 17.843914)
user system total real
Double Quotes 17.840000 0.000000 17.840000 ( 17.838304)
Single Quotes 18.060000 0.000000 18.060000 ( 18.058897)
user system total real
Double Quotes 18.430000 0.000000 18.430000 ( 18.431784)
Single Quotes 17.840000 0.000000 17.840000 ( 17.830713)
user system total real
Double Quotes 17.770000 0.000000 17.770000 ( 17.773707)
Single Quotes 17.840000 0.000000 17.840000 ( 17.839965)
user system total real
Double Quotes 17.810000 0.000000 17.810000 ( 17.806276)
Single Quotes 17.820000 0.000000 17.820000 ( 17.813905)
user system total real
Double Quotes 17.830000 0.000000 17.830000 ( 17.833804)
Single Quotes 17.820000 0.000000 17.820000 ( 17.820746)
user system total real
Double Quotes 17.840000 0.000000 17.840000 ( 17.836553)
Single Quotes 17.810000 0.000000 17.810000 ( 17.814055)
user system total real
Double Quotes 17.810000 0.000000 17.810000 ( 17.804322)
Single Quotes 17.830000 0.000000 17.830000 ( 17.829066)
user system total real
Double Quotes 17.790000 0.000000 17.790000 ( 17.790228)
Single Quotes 17.840000 0.000000 17.840000 ( 17.837580)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment