#39879 [Opn->Bgs]: strval not optimized

From: Date: Tue, 19 Dec 2006 14:34:38 +0000
Subject: #39879 [Opn->Bgs]: strval not optimized
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-106565@lists.php.net to get a copy of this message
ID: 39879 Updated by: tony2001@php.net Reported By: roberto at spadim dot com dot br -Status: Open +Status: Bogus Bug Type: Performance problem Operating System: ALL PHP Version: 5.2.0 New Comment: >we really need passed parameter? We do. >could we check if type is string, if it is string return >without convertion? That's exactly what it does. Previous Comments: ------------------------------------------------------------------------ [2006-12-19 14:26:16] roberto at spadim dot com dot br i read the source, but we really need passed parameter? could we check if type is string, if it is string return without convertion? can we optimize this function by this way? using &$str could have better performace? ------------------------------------------------------------------------ [2006-12-19 09:28:51] tony2001@php.net That's because you're comparing apples to oranges. Internal function has to copy the passed parameter, while userspace function may use copy-on-write, avoiding the malloc-memcpy-free cycle on each iteration. ------------------------------------------------------------------------ [2006-12-18 22:03:39] roberto at spadim dot com dot br Description: ------------ maybe strval isn't otimized see reproduce code Reproduce code: --------------- <?php function ret($st){return($st);} $qnt=1000000; $str=str_repeat("ae",1000); $st1=microtime(1); for ($i=0;$i<$qnt;$i++) ret($str); echo (microtime(1)-$st1)."\n"; $st1=microtime(1); for ($i=0;$i<$qnt;$i++) strval($str); echo (microtime(1)-$st1)."\n\n"; ?> Expected result: ---------------- expect to result 2 be small than result 1 Actual result: -------------- result 1 is bigger than 2 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39879&edit=1

« previous php.bugs (#106565) next »