<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Very interesting question! Here are the results (look at php5 !?)<br>
<br>
slantview:~ steverude$ /Applications/xampp/xamppfiles/bin/php-4.4.7
test.php <br>
Time for UPPERCASE: 720.796108246 ms<br>
<br>
Time for lowercase: 703.890800476 ms<br>
<br>
slantview:~ steverude$ /Applications/xampp/xamppfiles/bin/php-5.2.2
test.php <br>
Time for UPPERCASE: 617.037057877 ms<br>
<br>
Time for lowercase: 613.1939888 ms<br>
<br>
Just for testing sake, I also changed it to numeric 1 and ran it with
== instead of === (who uses === most of the time??)<br>
<br>
slantview:~ steverude$ /Applications/xampp/xamppfiles/bin/php-4.4.7
test.php <br>
Failed loading xdebug.so: (null)<br>
Time for UPPERCASE: 733.495235443 ms<br>
<br>
Time for lowercase: 712.421655655 ms<br>
<br>
slantview:~ steverude$ /Applications/xampp/xamppfiles/bin/php-5.2.2
test.php <br>
Failed loading xdebug.so: (null)<br>
Time for UPPERCASE: 623.962640762 ms<br>
<br>
Time for lowercase: 619.996070862 ms<br>
<br>
<br>
David Strauss wrote:
<blockquote cite="mid:46D32330.1020401@fourkitchens.com" type="cite">
<pre wrap="">What happens if you change the initial "$var = true;" into "$var = TRUE;"?
Steve Rude wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I ran this test just to see what would happen, and here are the results,
feel free to test it yourself. According to this test, running a simple
loop with one if statement 100k times, you lose about 20ms using
uppercase. What is interesting, is that the same test in php5 runs
100ms faster.
slantview:~ steverude$ /Applications/xampp/xamppfiles/bin/php-4.4.7
test.php
Time for UPPERCASE: 723.675251007 ms
Time for lowercase: 702.354669571 ms
slantview:~ steverude$ /Applications/xampp/xamppfiles/bin/php-5.2.2
test.php
Time for UPPERCASE: 622.086286545 ms
Time for lowercase: 607.203245163 ms
Another interesting stat is that we have 2383 times in a stock drupal
5.1 distribution where we use an uppercase TRUE, FALSE or NULL.
Reference:
slantview:~/Documents/workspace/drupal-5.1 steverude$ grep -r TRUE * | wc -l
629
slantview:~/Documents/workspace/drupal-5.1 steverude$ grep -r FALSE * |
wc -l
511
slantview:~/Documents/workspace/drupal-5.1 steverude$ grep -r NULL * | wc -l
1243
So it does not seem that unreasonable to me that we could potentially
get some performance gain by standardizing on lower case true, false and
null. Preference aside (me being on the uppercase side), I believe that
adding this standard to the drupal standards could potentially give us a
small amount of performance increase.
I also think the issue should be documented in the coding standard and
reflected in the Coder module regardless of the decision.
Here is the code for the test:
slantview:~ steverude$ cat test.php
<?php
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$var = true;
$time_total = 0;
for ($i = 0; $i < 100000; ++$i) {
$time_start = microtime_float();
if ($var === TRUE) {
$time_end = microtime_float();
$time_total += $time_end - $time_start;
}
}
$time_total = $time_total * 1000;
print "Time for UPPERCASE: $time_total ms\n\n";
$time_total = 0;
for ($i = 0; $i < 100000; ++$i) {
$time_start = microtime_float();
if ($var === true) {
$time_end = microtime_float();
$time_total += $time_end - $time_start;
}
}
$time_total = $time_total * 1000;
print "Time for lowercase: $time_total ms\n\n";
Thanks,
Steve Rude
Karoly Negyesi wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I do not believe that true could be faster than TRUE when php is case agnostic about its identifiers. Maybe there is time taken to lowercase TRUE ... but if you can measure lowercasing four characters in the parsing stage where only ASCII is supported, congratulations.
About commas, yes the D5 menu defintiions are ugly sometimes. Have you seen D6 :) ?
</pre>
</blockquote>
<pre wrap="">
--
Steve Rude + Lead Developer
*AchieveInternet*
(800) 618-877 x 202
<a class="moz-txt-link-freetext" href="http://www.achieveinternet.com">http://www.achieveinternet.com</a>
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
<br>
<br>
<div class="moz-signature">-- <br>
<font face="Verdana, Arial, Helvetica, sans-serif" size="2">Steve Rude
+ Lead Developer</font><br>
<b><font color="#ff3300" face="Verdana, Arial, Helvetica, sans-serif"
size="2">Achieve<font color="#666666">Internet</font></font></b><a><br>
<font face="Verdana, Arial, Helvetica, sans-serif" size="2">(800)
618-877 x 202</font><br>
<br>
<font face="Verdana, Arial, Helvetica, sans-serif" size="2">http://www.achieveinternet.com</font></a></div>
</body>
</html>