By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

Trivial question of execution speed

P: n/a
Hi,

I'm trying to write fast code, and I'm wondering which is faster,
generating strings with double quotes or single quotes - aka, $string
= "My name is $name"; or $string = 'My name is '.$name;.

Also, if you have any tips for writing fast code, please share
them :-).

Thanks,

--James.
Feb 15 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
jamesgoode wrote:
I'm trying to write fast code, and I'm wondering which is faster,
generating strings with double quotes or single quotes - aka, $string
= "My name is $name"; or $string = 'My name is '.$name;.
There is no noticeable
Also, if you have any tips for writing fast code, please share
them :-).
Skip premature optimization altogether[1], and concentrate on programming
efficient algorithms[2][3].

[1]http://en.wikipedia.org/wiki/Optimization_(computer_science)#When_to_optimize
[2]http://en.wikipedia.org/wiki/Computational_complexity_theory
[3]http://en.wikipedia.org/wiki/Big_O_notation

In other words, how you concatenate strings won't be a bottleneck in your
application. Unindexed databases or unnefficient ways to
search/update/manipulate data will be.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Con tecnología AMANO(tm).
Feb 15 '08 #2

P: n/a
..oO(jamesgoode)
>I'm trying to write fast code, and I'm wondering which is faster,
generating strings with double quotes or single quotes - aka, $string
= "My name is $name"; or $string = 'My name is '.$name;.
$string = sprintf('My name is %s', $name);

Yes, I've seen cases where this was faster than a sinqle-quoted string
with concatenation.

The point is: You won't notice any difference unless you call this line
a billion times. Google "premature optimization".
>Also, if you have any tips for writing fast code, please share
them :-).
Get a profiler to find the real bottlenecks in your code, _then_ start
thinking about optimization. Usually this means to modify the algorithm,
not the used language constructs. A poorly written QuickSort will still
almost always be faster than a highly optimized BubbleSort.

Micha
Feb 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.