measuring difference between single and double quotes
Moderator: General Moderators
Imagine a test:
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?
Code: Select all
$db->connect();
$rows = $db->fetchAll();
foreach ($rows as $row)
{
// do something with columns from $row and quotes
}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?
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
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?
Didn't know phpBB switched - I wonder what gains they experienced?
Source: http://area51.phpbb.com/docs/coding-guidelines.htmlThere 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.
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.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland