php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9260 Strange effects ...
Submitted: 2001-02-14 09:13 UTC Modified: 2001-02-14 09:19 UTC
From: stefan at digiconcept dot net Assigned:
Status: Closed Package: Performance problem
PHP Version: 4.0.4pl1 OS: Win NT, Service Pack 6, Apache 3
Private report: No CVE-ID: None
 [2001-02-14 09:13 UTC] stefan at digiconcept dot net
The following script only generates an array and walks through it with 2 different loops.
There are some strange effects while watching the durations of the loops.

1. Sometimes loop 1 is faster
1. Sometimes loop 2 is faster
1. Sometimes there is a negativ duration ... ?

PHP seems to behave in real bizarre way ... looks like it has a will of it's own ;-)

<?
function test()
{
 for ($i=0;$i<30000;$i++)
 {
  $GLOBALS['myVar'][$i]=$i;
 }
 $a = microtime();
 for ($i=0;$i<count($GLOBALS['myVar']);$i++)
 {
  $GLOBALS['myVar'][$i] = $GLOBALS['myVar'][$i] *2;
 }
 $b = microtime();
 foreach($GLOBALS['myVar'] as $i => $d)
 {
  $GLOBALS['myVar'][$i] = $d * 2;
 }
 $c = microtime();
 echo('Results ... <br>');
 echo("<b>$a<br>$b<br>$c</b><br>");
 list($m,$s)=explode(' ',$a);$a = doubleval($s)+doubleval($m);
 list($m,$s)=explode(' ',$b);$b = doubleval($s)+doubleval($m);
 list($m,$s)=explode(' ',$c);$c = doubleval($s)+doubleval($m);

 echo("<b>$a | $b | $c</b><br><br>");

 echo("Loop 1: ".($b-$a)." seconds<br>");
 echo("Loop 2: ".($c-$b)." seconds<br>");
 echo("<hr>");
}
test();test();test();test();test();
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-14 09:18 UTC] derick@php.net
This is not a performance problem, but a bug in the microtime function. It was recently fixed in CVS. Please try a snapshot from snaps.php.net. If the problem persists, please reopen this bugreport.
 [2001-02-14 09:18 UTC] cynic@php.net
1) microtime() isn't exactly microtime() on win32. IIRC it was improved somewhat _after_ the release of 4.0.4 pl1, but it still goes only to miliseconds. 

2) there are already bug reports concerning microtime.

bogusifying
 [2001-02-14 09:19 UTC] cynic@php.net
ah, concurrency...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC