Example #1
0
    return $stopTime - $startTime;
}
function whileBanchmark($array)
{
    $startTime = microtime(true);
    $i = 0;
    $count = sizeof($array);
    while ($i < $count) {
        $array[$i] = $array[$i] - 15;
        $i++;
    }
    $stopTime = microtime(true);
    return $stopTime - $startTime;
}
$testArr1 = createArr(1000000);
$testArr1_10000_s = createArr(1000000, 's');
//$testArr1_1000000 = [];
//$testArr2_100_100 = [];
//$testArr3_100_100_100 = [];
//
////$testArr1_1000000 = createArr($testArr1_1000000, 1000000);
//
//for ($j = 0; $j < 1000; $j++) {
//    $testArr2_100_100[$j] = createArr($testArr2_100_100, 1000);
//}
//for ($k = 0; $k < 100; $k++) {
//    for ($j = 0; $j < 100; $j++) {
//        $testArr3_100_100_100[$k][$j] = createArr($testArr3_100_100_100, 100);
//    }
//}
//echo '<pre>'; print_r($testArr3_100_100_100); echo '</pre>';
}
function printRes($for, $foreach, $while, $doWhile)
{
    unset($for[0], $while[0], $foreach[0], $doWhile[0]);
    $whileAv = array_sum($while) / sizeof($while);
    $doWhileAv = array_sum($doWhile) / sizeof($doWhile);
    $forAv = array_sum($for) / sizeof($for);
    $foreachAv = array_sum($foreach) / sizeof($foreach);
    $max = max($forAv, $foreachAv, $whileAv, $doWhileAv);
    $data = "<h2>От каждого елемена отнимаем 15, 100000 елементов масива</h2>\n" . 'test while - %' . $whileAv / $max * 100 . ' time: ' . $whileAv . "<br>\n" . 'test Do while - %' . $doWhileAv / $max * 100 . ' time: ' . $doWhileAv . "<br>\n" . 'test for - %' . $forAv / $max * 100 . ' time: ' . $forAv . "<br>\n" . 'test foreach - %' . $foreachAv / $max * 100 . ' time: ' . $foreachAv . "<br>\n";
    echo $data;
    $path = 'test---1Array(100000)_' . date('d_hms') . ".txt";
    //var_dump($path);
    file_put_contents($path, $data, FILE_APPEND);
}
//$testArr1 = createArr(1000);
//$testArr1 = createArr(10000);
$testArr1 = createArr(100000);
?>
<h1> Тест скорости циклов </h1>

<?php 
for ($j = 1; $j <= 2; $j++) {
    for ($i = 0; $i <= 10; $i++) {
        $foreach[$i] = foreachTest1($testArr1);
        $for[$i] = forTest1($testArr1);
        $while[$i] = whileTest1($testArr1);
        $doWhile[$i] = doWhileTest1($testArr1);
    }
    printRes($for, $foreach, $while, $doWhile);
}
    $doWhileAv = array_sum($doWhile) / sizeof($doWhile);
    $forAv = array_sum($for) / sizeof($for);
    $foreachAv = array_sum($foreach) / sizeof($foreach);
    $max = max($forAv, $foreachAv, $whileAv, $doWhileAv);
    $data = "<h2>От каждого елемена отнимаем 15, 3000x3000 елементов 2-хмерного масива</h2>\n" . 'test while - %' . $whileAv / $max * 100 . ' time: ' . $whileAv . "<br>\n" . 'test Do while - %' . $doWhileAv / $max * 100 . ' time: ' . $doWhileAv . "<br>\n" . 'test for - %' . $forAv / $max * 100 . ' time: ' . $forAv . "<br>\n" . 'test foreach - %' . $foreachAv / $max * 100 . ' time: ' . $foreachAv . "<br>\n\n";
    echo $data;
    $path = 'test---2Arrays_(3000)_' . date('d_hms') . ".txt";
    //var_dump($path);
    file_put_contents($path, $data, FILE_APPEND);
}
//$elements = 100;
//$elements = 1000;
$elements = 3000;
//for ($k = 0; $k < 100; $k++) {
for ($j = 0; $j < $elements; $j++) {
    $testArr[$j] = createArr($elements);
}
//}
//echo '<pre>'; print_r($testArr3_100_100_100); echo '</pre>';
?>
<h1> Тест скорости циклов </h1>

<?php 
for ($j = 1; $j <= 2; $j++) {
    for ($i = 0; $i <= 10; $i++) {
        $foreach[$i] = foreach_2Arrays($testArr);
        $while[$i] = while_2Arrays($testArr);
        $doWhile[$i] = doWhile_2Arrays($testArr);
        $for[$i] = for_2Arrays($testArr);
    }
    printRes($for, $foreach, $while, $doWhile);
Example #4
0
                    $where .= " and isfirst = 'T' ";
                    if (hasCondition($sex, $state, $country)) {
                        $where = setCondition($where, $sex, $state, $country);
                    }
                    if (hasTime($startMonth, $endMonth, $beforeMonth, $afterMonth, $onMonth)) {
                        $where = setInsertTime($where, $startMonth, $endMonth, $beforeMonth, $afterMonth, $onMonth);
                    }
                    if (hasUser($user)) {
                        $where = setUser($where, $user);
                    }
                } else {
                    echo "something wrong happens";
                    exit;
                }
            }
        }
    }
} else {
    echo "something wrong happens";
    exit;
}
$sql1 = $sql1 . $where;
$sql2 = $sql2 . $where;
// echo $sql1;
// echo PHP_EOL;
// echo $sql2;
// echo PHP_EOL;
$arr = createArr($sql1);
$count_distinct = countNum($sql2);
$result = array("count_distinct" => $count_distinct, "arr" => $arr);
print_r(json_encode($result));