<?php
$arrX = array(2, 4, 6, 8, 10, 12, 14, 16, 18, 20);
$arrY = array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
$iter = 100000;
$start = microtime(true);
$number_p = 3.14;
$distance = 40 / 5;
$total = 0;
for ($a = 0; $a < $iter; $a++) {
for ($i = 0; $i < count($arrX); $i++) {
for ($j = 0; $j < count($arrY); $j++) {
$value = ($arrX[$i] * ($number_p + $a)) * ($arrY[$j] + ($number_p * $distance));
switch ($i) {
case 3:
$total = $total + $value + 100;
break;
case 6:
$total = $total + $value + 500;
break;
case 9:
$total = $total + $value + 1000;
break;
default:
$total = $total + $value;
break;
}
if ($value % 2 == 0) {
$total = $total + 1;
}
if ($value % 2 != 0) {
$total = $total + 2;
}
}
}
}
echo "Total: $total";
$time = microtime(true) - $start;
echo "<br>Script time is $time";
$arrXcount = count($arrX);
$arrYcount = count($arrY);
for ($a = 0; $a < $iter; $a++) {
for ($i = 0; $i < $arrXcount; $i++) {
for ($j = 0; $j < $arrYcount; $j++) {
...
}
}
}
if ($value % 2 == 0) {
$total = $total + 1;
}
if ($value % 2 != 0) {
$total = $total + 2;
}
if ($value % 2 == 0) {
$total = $total + 1;
} else {
$total = $total + 2;
}
echo "Total: $total";
echo "<br>Script time is $time";
echo 'Total: ' . $total;
echo '<br>Script time is ' . $time;
for ($i = 0; $i < count($arrX); $i++) {
for ($j = 0; $j < count($arrY); $j++) {
$tmpValue = $arrX[$i] * ($arrY[$j] + ($number_p * $distance));
for ($a = 0; $a < $iter; $a++) {
$value = $tmpValue * ($number_p + $a);
<?php
$arrX = array(2, 4, 6, 8, 10, 12, 14, 16, 18, 20);
$arrY = array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
$iter = 100000;
$start = microtime(true);
$number_p = 3.14;
$distance = 40 / 5;
$total = 0;
$cntX = count($arrX);
$cntY = count($arrY);
$var0 = $number_p * $distance;
for ($a = 0; $a < $iter; $a++) {
$varA = $number_p + $a;
foreach ($arrX as $i => $x) {
$varB = $x * $varA;
foreach ($arrY as $j => $y) {
$value = $varB * ($y + $var0);
$total += $value;
switch ($i) {
case 3:
$total += 100;
break;
case 6:
$total += 500;
break;
case 9:
$total += 1000;
break;
}
if ($value % 2 == 0) {
$total = $total + 1;
} else {
$total = $total + 2;
}
}
}
}
echo "Total: $total";
$time = microtime(true) - $start;
echo "<br>Script time is $time";