|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-11-30 11:11 UTC] 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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 14:00:01 2025 UTC |
I suppose most of these type checking functions could be implemented as special types (much like strlen() is internally for constant strings). So in case a variable can be checked at compile time, the call can be optimized away. // Can be optimized (compile time) $name = 'Kalle'; if(is_string($name)) { } // Cannot be optimized (runtime), unless return type hinting is used (but what about NULL?) $name = getName(); if(is_string($name) { }