Page 4 of 4

Posted: Tue Apr 18, 2006 7:58 am
by feyd
in later versions of the phpBB 2.0.x branch they switched most, if not all strings to single quote that I remember.

Posted: Tue Apr 18, 2006 8:17 am
by dbevfat
Imagine a test:

Code: Select all

$db->connect();
$rows = $db->fetchAll();
foreach ($rows as $row)
{
  // do something with columns from $row and quotes
}
For 1M loops the difference between single and double quotes was about 0,2s -- as measured by other users in this thread, of course it depends on the amount of quote-juggling-code in the test. So, we could expect that for 10M loops the difference would be 2 seconds. The whole time would be over 100 seconds, but that doesn't matter, because both tests would take that much. The user would wait around 100s or 2 seconds more. He would never notice.

To sum up: something takes 102 seconds, and you can "improve" it to take "only" 100 seconds by replacing double quotes with single. Big optimization. Why not do something to get rid of those 100 seconds?

Posted: Tue Apr 18, 2006 9:09 am
by Oren
Are you kidding? I wish it took only 100 seconds. I'm not even going to do this test with 10M rows.
As you said "Imagine a test" :lol: no way I'm doing this test.

Posted: Tue Apr 18, 2006 9:44 am
by Maugrim_The_Reaper
Any such iterative test creates an aggregate execution time - sure that ups the measured time but still does nothing about individual runs where string quoting is likely negligible compared to bigger fish. Might as well connect to a database 10M times and blame it...;)

Didn't know phpBB switched - I wonder what gains they experienced?

Posted: Tue Apr 18, 2006 9:58 am
by Oren
There are two different ways to quote strings in PHP - either with single quotes or with double quotes. The main difference is that the parser does variable interpolation in double-quoted strings, but not in single quoted strings. Because of this, you should always use single quotes unless you specifically need variable interpolation to be done on that string. This way, we can save the parser the trouble of parsing a bunch of strings where no interpolation needs to be done.
Source: http://area51.phpbb.com/docs/coding-guidelines.html

I've found this page long time ago... They don't say anything related to the performance and speed but it's quite obvious that when PHP doesn't need to do any variable interpolation the code will run faster.

Posted: Tue Apr 18, 2006 9:59 am
by Maugrim_The_Reaper
The pudding is in the measurement of the gain...:)