[ create a new paste ] login | about

Link: http://codepad.org/odyUN0xg    [ raw code | output | fork ]

PHP, pasted on Mar 21:
<?php

$x = range(1,1000);
foreach($x as $key => $y)
{
   $x[$key] = range(1,1000);
   
}

$result=array();
$s = microtime();
foreach($x as $key => $y)
$result[$key] = array_sum($y);
$s2=microtime();
$s3=$s2-$s;
echo "array sum took $s3 seconds\n";

$result=array();
$z = microtime();
foreach($x as $key => $y)
{
  $result[$key] = 0;
  foreach($y as $num) $result[$key] += $num;
}
$z2=microtime();
$z3=$z2-$z;
echo "sum numbers took $z3 seconds";


Output:
1
2
array sum took 0.125188 seconds
sum numbers took 0.166603 seconds


Create a new paste based on this one


Comments: