Req #63655 [Com]: check type functions -> check type operators
| From: | jtrumbull at gmail dot com | Date: | Sun, 16 Mar 2014 01:56:32 +0000 |
| Subject: | Req #63655 [Com]: check type functions -> check type operators | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184799@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63655&edit=1
ID: 63655
Comment by: jtrumbull at gmail dot com
Reported by: sailormax at inbox dot lv
Summary: check type functions -> check type operators
Status: Open
Type: Feature/Change Request
Package: Performance problem
PHP Version: 5.3.19
Block user comment: N
Private report: N
New Comment:
it would appear cast conversion and comparison is only 2x faster when the result is TRUE, it is 3x
slower when the answer is FALSE
Previous Comments:
------------------------------------------------------------------------
[2013-01-02 13:01:59] vincent at lycoops dot be
This is true for simple scalars, yes.
But for large strings, array and objects, it is wrong.
But I agree that this should really be added.
------------------------------------------------------------------------
[2012-11-30 11:11:17] sailormax at inbox dot lv
Description:
------------
Currently check type functions (is_string, is_int, is_float, is_bool, is_object, is_array) are
functions. They are very often use in many engines. But because they are functions - they are very
slow for engines.
In result engine authors have to use faster alternatives (~2x faster) like:
is_string => ((string)$var === $var)
is_int => ((int)$var === $var)
is_float => ((float)$var === $var)
is_bool => ((bool)$var === $var)
is_object => ((object)$var === $var)
is_array => ((array)$var === $var)
Can you compile this type of functions as operators?
thank you.
Test script:
---------------
$ts = microtime(true);
for ($i=0; $i<50000; $i++) $res = is_string($_GET);
var_dump(microtime(true) - $ts);
print "<br /><br />";
$ts = microtime(true);
for ($i=0; $i<50000; $i++) $res = ((string)$_GET === $_GET);
var_dump(microtime(true) - $ts);
print "<br /><br />";
Expected result:
----------------
equal time
Actual result:
--------------
is_string ~ 2x slower than ((string)$_GET === $_GET)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63655&edit=1