예제 #1
0
 /**
  * Бенчмарк для проверки корректной работы и скорости кеша
  * @param bool $cache
  * */
 static function miniBenchmark($cache = true)
 {
     $t = [];
     $mark = function ($marker) use(&$t) {
         $t[$marker] = microtime(1);
         return $t[$marker];
     };
     $bulkObj = new BulkLib();
     $bulkObj->setCacheOn();
     if ($cache == false) {
         $cacheFlag = "<span style='color:red'>Кэш выключен</span>";
         $bulkObj->setCacheOff();
     } else {
         $cacheFlag = "<span style='color:#000'>Кэш включен</span>";
     }
     echo '</br><strong>[ Benchmark started: ' . $cacheFlag . ']</strong></br>';
     echo '</br><strong>Start:</strong>';
     echo $mark('one');
     echo ':#####################</br>';
     for ($i = 1; $i <= 15; $i++) {
         $bulkObj->prepareUserData(array(isset($_GET['user1']) ? (int) $_GET['user1'] : 1, isset($_GET['user2']) ? (int) $_GET['user2'] : 2, isset($_GET['user3']) ? (int) $_GET['user3'] : 12));
         echo $bulkObj->outUserData() . '-</br>';
     }
     echo '</br><strong>End:</strong>';
     echo $mark('two');
     echo '#####################</br>';
     echo "<b>Время работы скрипта, сек:</b>" . sprintf("%01.5f", $t['two'] - $t['one']);
     echo '</br></br><strong>[ Benchmark finished: ]</strong></br>';
 }