php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39879 strval not optimized
Submitted: 2006-12-18 22:03 UTC Modified: 2006-12-19 14:34 UTC
From: roberto at spadim dot com dot br Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.2.0 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: roberto at spadim dot com dot br
New email:
PHP Version: OS:

 

 [2006-12-18 22:03 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-19 09:28 UTC] 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-19 14:26 UTC] 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 14:34 UTC] tony2001@php.net
>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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 06:01:28 2024 UTC