Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 1.24 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## quotes_test.rb
  2.  
  3. require 'benchmark'
  4.  
  5. Benchmark.bm do |x|
  6.   x.report ("single quotes") do
  7.     for i in 1..10000000
  8.       s = '1234567890qwertyuiopasdfghjklzxcvbnm'
  9.     end
  10.   end
  11.  
  12.   x.report ("double quotes") do
  13.     for i in 1..10000000
  14.       s = "1234567890qwertyuiopasdfghjklzxcvbnm"
  15.     end
  16.   end
  17.  
  18.   x.report ("single quotes with concatenation") do
  19.     for i in 1..10000000
  20.       s = '1234567890qwertyuiopasdfghjklzxcvbnm' + i.to_s
  21.     end
  22.   end
  23.  
  24.   x.report ("double quotes with concatenation") do
  25.     for i in 1..10000000
  26.       s = "1234567890qwertyuiopasdfghjklzxcvbnm" + i.to_s
  27.     end
  28.   end
  29.  
  30.   x.report ("double quotes with embedding") do
  31.     for i in 1..10000000
  32.       s = "1234567890qwertyuiopasdfghjklzxcvbnm#{i}"
  33.     end
  34.   end
  35. end
  36.  
  37. # ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]
  38. #       user     system      total        real
  39. # single quotes  2.740000   0.010000   2.750000 (  2.745104)
  40. # double quotes  2.740000   0.000000   2.740000 (  2.748085)
  41. # single quotes with concatenation 11.420000   0.020000  11.440000 ( 11.428245)
  42. # double quotes with concatenation 11.400000   0.010000  11.410000 ( 11.403773)
  43. # double quotes with embedding 11.210000   0.030000  11.240000 ( 11.223446)