PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Trivial question of execution speed
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Trivial question of execution speed

Réponse
 
LinkBack Outils de la discussion
Vieux 15/02/2008, 13h11   #1
jamesgoode
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Trivial question of execution speed

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.
  Réponse avec citation
Vieux 15/02/2008, 13h41   #2
Iván Sánchez Ortega
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trivial question of execution speed

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).
  Réponse avec citation
Vieux 15/02/2008, 23h12   #3
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trivial question of execution speed

..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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h22.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09997 seconds with 11 queries