Trivial question of execution speed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jamesgoode

    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.
  • =?ISO-8859-15?Q?Iv=E1n_S=E1nchez_Ortega?=

    #2
    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.or g/wiki/Optimization_(c omputer_science )#When_to_optim ize
    [2]http://en.wikipedia.or g/wiki/Computational_c omplexity_theor y
    [3]http://en.wikipedia.or g/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).

    Comment

    • Michael Fesser

      #3
      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

      Comment

      Working...