On Fri, 10 May 2002, Austin Marshall wrote:
>> I wonder if it matters from an overhead point of view, is PHP doing
>> more work than it ought to using " instead of ' because it's expecting
>> variables?
> I'd be interested to see if there were much a difference 
> performance-wise though.

Quick-and-dirty speed test (comments on my methodology are welcome):

  $z = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4);
  list ($msec, $sec) = explode(' ', microtime());
  $start_time = $msec + $sec;
  $total = 0;
  for ($i = 0; $i < 100000; $i++)
    $total += $z["three"];
  list ($msec, $sec) = explode(' ', microtime()); 
  printf ('Elapsed: %f seconds.', ($msec + $sec) - $start_time); 


I ran it this way and then changed the $total += line to use 'single 
quotes' instead of "double". 

There was no noticeable difference in times; the variation from one run to 
the next (between 0.33 and 0.35 seconds) was far greater than the 
variation between quote types.

Nevertheless I find myself irresistably compelled to keep using the single
quotes when I know no string variable substitution is required. Call me an
irrational old fool.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to