[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: "" vs ''

Justin Collins

7/20/2006 6:57:00 PM

Ben Johnson wrote:
> I know this is a very simply question, but I've seen many different
> responses.
>
> Isn't it better to use 'some string' instead of "some string". Because
> the "" goes through a lot more working interpreting any variable that
> might be in the string, etc. Where as '' is just literal.
>
> Thanks for your help.
>
> Thank You,
> Ben Johnson
> E: bjohnson@contuitive.com

I like to think it makes a difference, but...

Don't know if this is a good benchmark or not (probably not):

require 'benchmark'
include Benchmark

bmbm(10) { |r|
r.report('Literal') {
1000000.times {

'asdjasdjpaidjpoasjdsadsadajpsodjaposdjpaojvpdoasjpdoajs
pdoBaspdojaspodjpaowjeAo'
}
}
r.report('Interpolated') {
1000000.times {

"asdjasdjpaidjpoasjdsadsadajpsodjaposdjpaojvpdoasjpdoajs
pdoBaspdojaspodjpaowjeAo"
}
}
}



Rehearsal ------------------------------------------------
Literal 0.480000 0.000000 0.480000 ( 0.494254)
Interpolated 0.480000 0.000000 0.480000 ( 0.492916)
--------------------------------------- total: 0.960000sec

user system total real
Literal 0.490000 0.000000 0.490000 ( 0.546283)
Interpolated 0.490000 0.000000 0.490000 ( 0.501239)