Exemplo n.º 1
0
 /**
  * Create, configure and call Statement
  *
  * @param $str_sql
  * @param null $arr_params
  * @param String $str_result_class
  * @param int $int_fetch_mode
  * @return array|NULL|void
  */
 private function delegateFetch($str_sql, $arr_params, $str_result_class, $int_fetch_mode)
 {
     $obj_stmt = new DB\Statement($this->obj_db, $str_sql);
     if ($str_result_class) {
         $obj_stmt->setResultClass($str_result_class);
     }
     if (self::FETCH_MODE_ONE === $int_fetch_mode) {
         return $obj_stmt->fetchOne($arr_params);
     } else {
         return $obj_stmt->fetchAll($arr_params);
     }
 }
Exemplo n.º 2
0
/**
 * Time a callback function.
 *
 * Execute callback 'n' times in 'm' loops and calculate the average
 *
 * @param string $str_name
 * @param $callback
 * @param int $int_times
 * @param int $int_loops
 * @return array
 */
function timeit($str_name, $callback, $int_times = 3, $int_loops = 2000)
{
    echo str_pad($str_name, 50);
    $arr_times = array();
    $flt_total = 0.0;
    for ($n = 0; $n < $int_times; $n++) {
        $start = microtime(TRUE);
        for ($i = 0; $i < $int_loops; $i++) {
            $callback();
        }
        $flt_time = round(microtime(TRUE) - $start, 4);
        $flt_total += $flt_time;
        $arr_times[] = $flt_time;
    }
    echo "{$int_times}/avg: " . round($flt_total / $int_times, 4) . "s\n";
}
echo "\n\n=========================================\n";
echo "Statements: " . print_r(\Docnet\DB\Statement::getStats(), TRUE);
echo "Memory: " . round(memory_get_usage() / 1024 / 1024, 2) . "MB (peak " . round(memory_get_peak_usage() / 1024 / 1024, 2) . ")\n";
echo "\nDone\n";