Req #63655 [Com]: check type functions -> check type operators
Edit report at https://bugs.php.net/bug.php?id=63655&edit=1
ID: 63655
Comment by: vincent at lycoops dot be
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:
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.
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)