Skip to content

Instantly share code, notes, and snippets.

@NewFuture
Created August 18, 2016 12:54
Show Gist options
  • Save NewFuture/cbed2f370026da01f715ecbe9bbb375b to your computer and use it in GitHub Desktop.
Save NewFuture/cbed2f370026da01f715ecbe9bbb375b to your computer and use it in GitHub Desktop.
<?php
// Initial Configuration
global $aHash;
$i = 0;
$tmp = '';
while($i < 100) {
$tmp .= 'a';
++$i;
}
$aHash = array_fill(-10, 30, $tmp);
unset($i, $tmp);
// Test Source
function Test2_3($aHash) {
/* The Test */
$t = microtime(true);
for ($k=0; $k < 1000; $k++) {
$key = array_keys($aHash);
$size = sizeOf($key);
for ($i=0; $i<$size; $i++) $aHash[$key[$i]] .= "a";
}
return (microtime(true) - $t)*1000000;
}
// Test Source
function Test2_1($aHash) {
/* The Test */
$t = microtime(true);
for ($i=0; $i < 1000; $i++) {
// reset($aHash);
foreach($aHash as $key=>$val) $aHash[$key] .= "a";
}
return (microtime(true) - $t)*1000000;
}
// Test Source
function Test2_2($aHash) {
/* The Test */
$t = microtime(true);
for ($i=0; $i < 1000; $i++) {
// reset($aHash);
foreach($aHash as &$val) $val .= "a";
}
return (microtime(true) - $t)*1000000;
}
// Variable Clean-up
function Test2_End() {
global $aHash;
unset($aHash);
}
$t2=Test2_2($aHash);
$t1=Test2_1($aHash);
$t3=Test2_3($aHash);
echo "t1:",$t1,"\nt2:",$t2,"\nt3:",$t3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment