#23721 [Bgs]: TRUE and FALSE constants slower than keywords in previous versions

From: Date: Wed, 21 May 2003 01:08:24 +0000
Subject: #23721 [Bgs]: TRUE and FALSE constants slower than keywords in previous versions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-40109@lists.php.net to get a copy of this message
ID: 23721 Updated by: sniper@php.net Reported By: max at fuck dot org Status: Bogus Bug Type: Performance problem Operating System: FreeBSD PHP Version: 4.3.1 New Comment: In real life applications you really won't notice any difference. And the lowercase version of any constant defined as case-insensitive will always be looked up faster. (ie. true is looked for first, then if not found, TRUE) Previous Comments: ------------------------------------------------------------------------ [2003-05-20 19:12:25] max at fuck dot org no, i think it's great the performance is better, but all of a sudden there is a performance difference between using true and TRUE. if true is (as it would seem) the faster and more efficient way of using the keyword, maybe someone should go through the documentation and make a note of that? ------------------------------------------------------------------------ [2003-05-20 18:00:24] sniper@php.net If better performance is a problem for you, maybe you should consider using some slower language? :) There is no bug. ------------------------------------------------------------------------ [2003-05-20 11:43:18] max at fuck dot org -bash-2.05b$ cat true_test.php <?php /* -*- C++ -*- */ function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $time_start = getmicrotime(); for ($i = 0; $i <= 1000000; $i++) { if ($i % 2) { $n = true; } else { $n = false; } if ($n == true) { } else if ($n == false) { } } $time_end = getmicrotime(); $time = $time_end - $time_start; echo "true/false:\t $time seconds.\n"; $time_start = getmicrotime(); for ($i = 0; $i <= 1000000; $i++) { if ($i % 2) { $n = TRUE; } else { $n = FALSE; } if ($n == TRUE) { } else if ($n == FALSE) { } } $time_end = getmicrotime(); $time = $time_end - $time_start; echo "TRUE/FALSE:\t $time seconds.\n"; ?> -bash-2.05b$ php -v 4.2.3 -bash-2.05b$ uname -a FreeBSD 4.8-RELEASE FreeBSD 4.8-RELEASE #0: Thu Apr 3 10:53:38 GMT 2003 -bash-2.05b$ php true_test.php X-Powered-By: PHP/4.2.3 Content-type: text/html true/false: 5.9379440546036 seconds. TRUE/FALSE: 5.9383209943771 seconds. <configure/make/make install-cli 4.3.1 (no special config options)> -bash-2.05b$ php -v PHP 4.3.1 (cli) (built: May 20 2003 11:15:26) Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies -bash-2.05b$ php true_test.php true/false: 4.2005170583725 seconds. TRUE/FALSE: 5.1550530195236 seconds. <configure/make/make install-cli latest snapshot (no special config options)> PHP 4.3.2RC4-dev (cli) (built: May 20 2003 11:41:28) Copyright (c) 1997-2003 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies -bash-2.05b$ php true_test.php true/false: 4.2775070667267 seconds. TRUE/FALSE: 5.1591459512711 seconds. I've tested this on multiple machines, seems that anything newer than 4.3.0 has this issue. Although I haven't looked myself I was told that recently TRUE and FALSE are now defined as constants rather than keywords. While these are both faster than the previous version(s), if this difference in speed was intended, it wasn't documented anywhere. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23721&edit=1

« previous php.bugs (#40109) next »