<?php

//ini_set("memory_limit", -1);

$array  = Array();
$array2 = new ArrayObject();

for(
$x 0$x != 1000$x++)
{
  
array_push($array$x);
}
for(
$x 0$x != 1000$x++)
{
  
$array2->append($x);
}

/*
 * foreach() on Array()
 */
$memory memory_get_usage();
$time microtime(true);
foreach(
$array as $key => $value){
  
$tmp $key ." => "$value ."\n";
}
$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"foreach() on Array() took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * for() on Array()
 */
$memory memory_get_usage();
$time microtime(true);
for(
$x 0$x != 1000$x++){
  
$tmp $x ." => "$array[$x] ."\n";
}
$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"for() on Array() took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * while() on Array()
 */
$memory memory_get_usage();
$time microtime(true);
$x    0;
while(
$x != 1000){
  
$tmp $x ." => "$array[$x] ."\n";
  
$x++;
}
$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"while() on Array() took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * foreach() on ArrayIterator
 */
$memory memory_get_usage();
$time microtime(true);
$it   $array2->getIterator();
foreach(
$it as $key => $value){
    
$tmp $key ." => "$value ."\n";
}
$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"foreach() on ArrayIterator took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * for() on ArrayIterator
 */
$memory memory_get_usage();
$time microtime(true);
$it   $array2->getIterator();
for(;
$it->valid();$it->next()){
  
$tmp $it->key() ." => "$it->current() ."\n";
}
$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"for() on ArrayIterator took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * while() on ArrayIterator
 */
$memory memory_get_usage();
$time microtime(true);
$it   $array2->getIterator();
while(
$it->valid()){
  
$tmp $it->key() ." => "$it->current() ."\n";
  
$it->next();
}
$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"while() on ArrayIterator took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

?>