com phpruntests: phpruntests - add arrayTest (spl-performace-test): code-samples/arrayTest.php

From: Date: Sun, 21 Jun 2009 17:30:46 +0000
Subject: com phpruntests: phpruntests - add arrayTest (spl-performace-test): code-samples/arrayTest.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-66409@lists.php.net to get a copy of this message
Commit: ff08eea2839447dc2a3508b5f3699dfa2a7cdb4b Author: Georg Gradwohl <g2@php.net> Sun, 21 Jun 2009 17:30:46 +0000 Parents: 4127cd748679f8bf2e4abc4968c877138c3703ed Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=ff08eea2839447dc2a3508b5f3699dfa2a7cdb4b Log: phpruntests - add arrayTest (spl-performace-test) Changed paths: A code-samples/arrayTest.php Diff: diff --git a/code-samples/arrayTest.php b/code-samples/arrayTest.php new file mode 100644 index 0000000..ff2bdb4 --- /dev/null +++ b/code-samples/arrayTest.php @@ -0,0 +1,70 @@ +<?php + +$size = isset($argv[1]) ? $argv[1] : 99999; + + +// create array + +$testArray = array(); + +for ($i=0; $i<$size; $i++) { + + $testArray[$i] = rand(0,9); +} + +print "size:\t$size\n"; +flush(); + + +// loop + +$s = microtime(true); + +for ($i=0; $i<$size; $i++) { + + if (isset($testArray[$i])) { + + if ($i%2 == 0) { + + $testArray[$i] = 'G'; + } + } +} + +$e = microtime(true); + +$tl = round($e-$s, 5); + +print "loop:\t$tl sec (100%)\n"; +flush(); + + +// iterator + +$s = microtime(true); + +$testObject = new ArrayObject($testArray); +$iterator = $testObject->getIterator(); + +while ($iterator->valid()) { + + if ($iterator->key()%2 == 0) { + + $testObject[$iterator->current()] = 'G'; + } + + $iterator->next(); +} + +$e = microtime(true); + +$ti = round($e-$s, 5); + +$diff = round($ti/$tl*100, 0); + +print "spl:\t$ti sec ($diff%)\n"; +print "DIFF:\t".($ti-$tl)." sec\n"; +flush(); + + +?> \ No newline at end of file

« previous php.qa (#66409) next »