/**
 * Show benchmark table
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_benchmark($params, &$smarty)
{
    if (DEBUG < DEBUG_DEVELOPMENT) {
        return '';
    }
    // if
    $benchmark =& BenchmarkTimer::instance();
    $db =& DBConnection::instance();
    $result = array('Executed in: ' . (double) number_format($benchmark->TimeElapsed(), 3) . 's', 'SQL queries: ' . $db->query_counter);
    if (function_exists('memory_get_usage')) {
        $result[] = 'Memory usage: ' . number_format(memory_get_usage() / 1048576, 2, '.', ',') . 'MB';
    }
    // if
    return '<p id="benchmark">' . implode('. ', $result) . '</p>';
}
/**
 * Display data that timer collected
 *
 * @access public
 * @param boolean $show_total Show total time
 * @param boolean $display Render or return
 * @return mixed
 */
function benchmark_timer_display($full = true)
{
    $timer =& BenchmarkTimer::instance();
    $timer->display($full);
}
/**
 * Set marker
 *
 * @param string $marker_name Marker name
 * @return null
 */
function benchmark_timer_set_marker($marker_name)
{
    $timer =& BenchmarkTimer::instance();
    $timer->setMarker($marker_name);
}
Exemple #4
0
<?php

include '../BenchmarkTimer.php';
$totalMemory = memory_get_usage($real);
$benchmark = new BenchmarkTimer(false);
$real = false;
// on se connect à localhost au port 3307
$link = mysql_connect('127.0.0.1', 'root', 'root');
if (!$link) {
    die('Connexion impossible : ' . mysql_error());
}
if (!mysql_select_db('classicmodels', $link)) {
    echo 'Sélection de base de données impossible';
    exit;
}
//$sqlMax = "SELECT max(officeCode) FROM offices";
//$result = mysql_query($sqlMax, $link);
//
//$array = mysql_fetch_array($result);
//$maxOfficeCode = $array[0];
//var_dump($maxOfficeCode);
//exit;
function geResult($sql, $link, $action = false)
{
    if ('insert' == $action) {
        for ($i = 100; $i <= 1100; $i++) {
            $sql = "INSERT INTO offices(officeCode, city, phone, addressLine1, country, postalCode, territory)\nVALUES({$i}, 'Paris', '0123456789', 'address ligne 1', 'FRANCE', '75012', 'FR');";
            $result = mysql_query($sql);
            //            if (!$result) {
            //                echo "Erreur DB, impossible d'effectuer une requête\n";
            //                echo 'Erreur MySQL : ' . mysql_error();
Exemple #5
0
    return htmlentities($text);
}
/**
 * @param  int
 * @param  string
 * @param  string
 * @return void
 */
function http_error($status, $title, $html)
{
    require_once MVC_DIR . 'event.d/http_error.php';
}
########################################################################
# init dev stuff - we keep it here instead of event.d because the dev performance is important.
if (MVC_DEV_MODE) {
    $benchmarkTimer = new BenchmarkTimer();
    BenchmarkTimer::$utf8 = 0;
    $benchmarkTimer->start();
    $_mvc_dev_can_print = null;
    /**
     * @return bool
     * @ignore
     */
    function mvc_dev_can_print()
    {
        global $_mvc_dev_can_print;
        if ($_mvc_dev_can_print !== null) {
            return $_mvc_dev_can_print;
        }
        foreach (headers_list() as $h) {
            if (strcasecmp(substr($h, 0, 12), 'content-type') == 0) {
Exemple #6
0
            }
            if ($sec > 1.0E-6 && $what == null || $what == 'mi' || $what == 'mu' || $what == "µs" || $what == "Âs" || $what == 'us') {
                return round($sec * 1000000, 2) . ' ' . (self::$utf8 ? "µ" : 'u') . 's';
            }
            return intval($sec * 1000000000) . ' ns';
        }
    }
    private function rus($end)
    {
        if (self::$HAVE_RUSAGE) {
            $this->buff = getrusage();
            if ($end) {
                $this->rtime = microtime(true) - $this->rtime;
                $this->utime = $this->buff["ru_utime.tv_sec"] . $this->buff["ru_utime.tv_usec"] - $this->utime;
                $this->stime = $this->buff["ru_stime.tv_sec"] . $this->buff["ru_stime.tv_usec"] - $this->stime;
            } else {
                $this->rtime = microtime(true);
                $this->utime = $this->buff["ru_utime.tv_sec"] . $this->buff["ru_utime.tv_usec"];
                $this->stime = $this->buff["ru_stime.tv_sec"] . $this->buff["ru_stime.tv_usec"];
            }
        } else {
            if ($end) {
                $this->rtime = microtime(true) - $this->rtime;
            } else {
                $this->rtime = microtime(true);
            }
        }
    }
}
BenchmarkTimer::$HAVE_RUSAGE = function_exists('getrusage');