Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Created August 10, 2013 13:14
Show Gist options
  • Save the-teacher/6200406 to your computer and use it in GitHub Desktop.
Save the-teacher/6200406 to your computer and use it in GitHub Desktop.
Interpolation vs concatenation
1.8.7 :009 > Benchmark.bm{ |b| b.report{ 100_000.times{ Rails.root + 'a/b/c' } } }
user system total real
4.890000 0.010000 4.900000 ( 5.407428)
=> true
1.8.7 :010 > Benchmark.bm{ |b| b.report{ 100_000.times{ Rails.root.to_s + 'a/b/c' } } }
user system total real
0.220000 0.000000 0.220000 ( 0.272255)
=> true
1.8.7 :011 > Benchmark.bm{ |b| b.report{ 100_000.times{ "#{Rails.root}/a/b/c" } } }
user system total real
0.190000 0.000000 0.190000 ( 0.212162)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment