|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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). |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
..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 |
|
![]() |
| Outils de la discussion | |
|
|