/**
  * @access public
  */
 protected function runTest()
 {
     $timer = new Benchmark_Timer();
     $timer->start();
     parent::runTest();
     $timer->stop();
     if ($this->fMaxRunningTime != 0 && $timer->timeElapsed() > $this->fMaxRunningTime) {
         PHPUnit_Framework_Assert::fail(sprintf('expected running time: <= %s but was: %s', $this->fMaxRunningTime, $timer->timeElapsed()));
     }
 }
 /**
  * Cleanly end the current test
  */
 protected function endCurrentTest()
 {
     if (!$this->currentTest || !$this->currentSuite) {
         return;
     }
     // Time the current test
     $testDuration = microtime(true) - $this->startTestTime;
     $this->testSpeeds[$this->currentSuite['suite']->getName() . '.' . $this->currentTest['name']] = $testDuration;
     if ($this->hasTimer) {
         $this->timer->stop();
         $this->currentTest['timeElapsed'] = $this->timer->timeElapsed();
     }
     // Save and reset current state
     array_push($this->currentSuite['tests'], $this->currentTest);
     $this->currentTest = null;
 }
$sql = "drop table if exists users_no_partition";
$result = bmark_query($sql, $dbh);
# print $sql . "\n";
$sql = "CREATE TABLE users_no_partition ( id INT NOT NULL primary key AUTO_INCREMENT , login varchar(255), email varchar(255), im varchar(255), twitter varchar(255), pass varchar(255), datejoined datetime) ENGINE=InnoDB DEFAULT CHARSET=utf8";
$result = bmark_query($sql, $dbh);
# print $sql . "\n";
$sql = 'create index login_index on users_no_partition (login)';
$result = bmark_query($sql, $dbh);
# print $sql . "\n";
for ($i = 0; $i < $max_rows; $i++) {
    $sql = "insert into users_no_partition (login, pass) values (\"" . md5(rand(1, 5000) . microtime()) . "user{$i}\", \"" . md5("pass{$i}") . "\")";
    $result = bmark_query($sql, $dbh);
    # print $sql . "\n";
}
$timer->setMarker('No_Partition');
echo "Elapsed time between Start and Test_Code_Partition: " . $timer->timeElapsed('Start', 'No_Partition') . "\n";
$prefix = "users_";
$k = 1;
for ($i = 0; $i < $parts; $i++) {
    $table = $prefix . padNumber($i, 2);
    $sql = "drop table if exists {$table}";
    # print "table: $table\n";
    # print $sql . "\n";
    $result = bmark_query($sql, $dbh);
    $sql = "CREATE TABLE {$table} ( id INT NOT NULL primary key AUTO_INCREMENT , login varchar(255), email varchar(255), im varchar(255), twitter varchar(255), pass varchar(255), datejoined datetime)  ENGINE=InnoDB DEFAULT CHARSET=utf8";
    $result = bmark_query($sql, $dbh);
    $sql = "create index login_index on {$table} (login)";
    $result = bmark_query($sql, $dbh);
    for ($j = 0; $j < $perpart; $j++) {
        $sql = "insert into {$table} (id, login, pass) values ({$k}, \"" . md5(rand(1, 5000) . microtime()) . "user{$j}\", \"" . md5('pass$j') . "\")";
        $result = bmark_query($sql, $dbh);
Exemple #4
0
<?php

require 'Benchmark/Timer.php';
$timer = new Benchmark_Timer();
$mysql = new mysqli("localhost", "testuser", "testpass", "test");
$points = array(1000, 10000, 100000, 500000, 1000000);
foreach ($points as $val) {
    flush_mysql();
    $startmark = $val . ' start';
    $stopmark = $val . ' stop';
    $timer->setMarker($startmark);
    cycle($val);
    $timer->setMarker($stopmark);
    print $val . ': ' . $timer->timeElapsed($startmark, $stopmark) . "\n";
}
$mysql->close();
function flush_mysql()
{
    global $mysql;
    $mysql->query("DROP TABLE IF EXISTS `php_insert_bm`");
    $mysql->query("DROP TABLE IF EXISTS `php_insert_bm_coords`");
    $mysql->query("CREATE TABLE `php_insert_bm_coords`(\n    `id` int unsigned not null auto_increment,\n    `x` int not null,\n    `y` int not null,\n    PRIMARY KEY (`id`)\n  )");
    $mysql->query("CREATE TABLE `php_insert_bm`(\n    `id` int unsigned not null auto_increment,\n    `text` varchar(255) not null,\n    `count` int not null,\n    `coords_id` int unsigned not null,\n    PRIMARY KEY (`id`)\n  )");
    # empty init entries
    $mysql->query("INSERT php_insert_bm_coords(x,y) VALUES(0, 0)");
    $mysql->query("INSERT php_insert_bm(text, count, coords_id) VALUES('', 0, " . $mysql->insert_id . ')');
}
function cycle($c)
{
    global $mysql;
    for ($i = 0; $i < $c; $i++) {
Exemple #5
0
        break;
    case 'infolinks':
        $_module = 'infolinks';
        break;
    case 'jobs':
        $_module = 'jobs';
        break;
    default:
        // $_module='notfound';
        $_module = 'news';
}
include 'modules/' . $_module . '/' . $_module . $cfg['suffix']['code'];
// append
$tpl->setVariable("LEFTNAV", $nav->get());
$tpl->setvariable($content);
$tpl->show();
$cache->endPrint(+1000);
if (DEBUG) {
    echo 'cache miss<br>';
}
/*}
else {
    $cache->printContent();
    if(DEBUG){
        echo 'cache hit<br>';
    }
}     */
if (BENCHMARK) {
    $timer->stop();
    echo '<small>php created this page in ' . $timer->timeElapsed() . ' seconds</small>';
}
Exemple #6
0
/**
 * Выполнение sql-запроса
 *
 * @param string запрос
 *
 * @global $nc_core
 *
 * @return bool выполнился запрос или нет
 */
function ExecuteSQLQuery($Query)
{
    global $nc_core;
    $SHOW_MYSQL_ERRORS = $nc_core->SHOW_MYSQL_ERRORS;
    $db = $nc_core->db;
    // таймер
    $nccttimer = new Benchmark_Timer();
    $Query = trim(stripslashes($Query));
    $db->query("DELETE FROM `SQLQueries` WHERE MD5(`SQL_text`) = '" . md5($Query) . "' ");
    // если в истории запросов больше 15, то нужно удалить
    if ($db->get_var("SELECT COUNT(`SQL_ID`) FROM `SQLQueries`") >= 15) {
        $db->query("DELETE FROM `SQLQueries` ORDER BY `SQL_ID` LIMIT 1");
    }
    $db->query("INSERT INTO SQLQueries (SQL_ID, SQL_text) VALUES ('', '" . $db->escape($Query) . "')");
    // скроем ошибки в случае неправильного запроса, чтобы вывести свое сообщение об ошибке
    $db->hide_errors();
    // выполение запроса
    $nccttimer->start();
    $res = $db->get_results(stripslashes($Query), ARRAY_A);
    $nccttimer->stop();
    // если показ ошибок MySQL включен, то включим его обратно
    if ($SHOW_MYSQL_ERRORS == 'on') {
        $db->show_errors();
    }
    if ($db->captured_errors) {
        echo "<br /><b>Query:</b> " . $db->captured_errors[0][query] . "<br><br><b>Error:</b> " . $db->captured_errors[0][error_str] . "<br /><br />";
        return false;
    }
    $count = $db->num_rows;
    // вывод таблицы с результатом, если нет ошибок
    if ($res && $count) {
        echo "<br /><b>" . htmlspecialchars(stripslashes($Query)) . "</b><br /><br />";
        $data = $res;
        echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n            <tr><td>\n              <table class='admin_table sql_table' width='100%'><tr>";
        //вывод полей
        while (list($key, $val) = each($res[0])) {
            echo "<td><font>" . $key . "</td>";
        }
        echo "</tr>";
        reset($res[0]);
        for ($i = 0; $i < $count; $i++) {
            echo "<tr>";
            while (list($key, $val) = each($res[$i])) {
                echo "<td><font> " . htmlspecialchars($res[$i][$key]) . "</td>";
            }
            echo "</tr>";
        }
        echo "</table></td></tr></table><br>";
        $res_num = $count ? $count : $db->rows_affected;
    } elseif (!$res) {
        if (preg_match("/^(insert|delete|update|replace)\\s+/i", $db->last_query)) {
            $res_num = $db->rows_affected;
        } else {
            $res_num = $db->num_rows;
        }
    }
    echo "<div>" . TOOLS_SQL_OK . "</div>";
    echo "<div>" . TOOLS_SQL_TOTROWS . ": " . $res_num . "</div>";
    echo "<div>" . TOOLS_SQL_BENCHMARK . ": " . $nccttimer->timeElapsed() . "</div>";
    echo "<br />";
}
 * @package   Benchmark
 * @author    Sebastian Bergmann <*****@*****.**>
 * @copyright 2002-2005 Sebastian Bergmann <*****@*****.**>
 * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
 * @version   CVS: $Id: timer_example.php 268884 2008-11-12 20:57:49Z clockwerx $
 * @link      http://pear.php.net/package/Benchmark
 */
require '../library/Timer.php';
/**
 * Wait
 *
 * @param int $amount Amount to wait
 *
 * @return void
 */
function wait($amount)
{
    for ($i = 0; $i < $amount; $i++) {
        for ($i = 0; $i < 100; $i++) {
        }
    }
}
// Pass the param "true" to constructor to automatically display the results
$timer = new Benchmark_Timer();
$timer->start();
wait(10);
$timer->setMarker('Mark1');
echo "Elapsed time between Start and Mark1: " . $timer->timeElapsed('Start', 'Mark1') . "\n";
wait(50);
$timer->stop();
$timer->display();
 /**
  * @param  PHPUnit2_Framework_Test $suite
  * @param  boolean                 $wait
  * @return PHPUnit2_Framework_TestResult
  * @access public
  */
 public function doRun(PHPUnit2_Framework_Test $suite, $wait = false)
 {
     $result = $this->createTestResult();
     if ($this->printer === null) {
         $this->printer = new PHPUnit2_TextUI_ResultPrinter();
     }
     $this->printer->write(PHPUnit2_Runner_Version::getVersionString() . "\n\n");
     $result->addListener($this->printer);
     if (class_exists('Benchmark_Timer')) {
         $timer = new Benchmark_Timer();
     }
     if (isset($timer)) {
         $timer->start();
     }
     $suite->run($result);
     if (isset($timer)) {
         $timer->stop();
         $timeElapsed = $timer->timeElapsed();
     } else {
         $timeElapsed = false;
     }
     $this->pause($wait);
     $this->printer->printResult($result, $timeElapsed);
     return $result;
 }
Exemple #9
0
 /**
  * A test ended.
  *
  * @param  PHPUnit2_Framework_Test $test
  * @access public
  */
 public function endTest(PHPUnit2_Framework_Test $test)
 {
     $this->timer->stop();
     $time = $this->timer->timeElapsed();
     $this->currentTestCase->setAttribute('time', $time);
     $this->testSuiteTimes[$this->testSuiteLevel] += $time;
     $this->currentTestCase = NULL;
 }
Exemple #10
0
 /**
  * @param  PHPUnit2_Framework_Test $suite
  * @param  mixed                   $coverageDataFile
  * @param  mixed                   $coverageHTMLFile
  * @param  mixed                   $coverageTextFile
  * @param  mixed                   $testdoxHTMLFile
  * @param  mixed                   $testdoxTextFile
  * @param  mixed                   $xmlLogfile
  * @param  boolean                 $wait
  * @return PHPUnit2_Framework_TestResult
  * @access public
  */
 public function doRun(PHPUnit2_Framework_Test $suite, $coverageDataFile = FALSE, $coverageHTMLFile = FALSE, $coverageTextFile = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $xmlLogfile = FALSE, $wait = FALSE)
 {
     $result = $this->createTestResult();
     $timer = new Benchmark_Timer();
     if ($this->printer === NULL) {
         $this->printer = new PHPUnit2_TextUI_ResultPrinter();
     }
     $this->printer->write(PHPUnit2_Runner_Version::getVersionString() . "\n\n");
     $result->addListener($this->printer);
     if ($testdoxHTMLFile !== FALSE || $testdoxTextFile !== FALSE) {
         require_once 'PHPUnit2/Util/TestDox/ResultPrinter.php';
         if ($testdoxHTMLFile !== FALSE) {
             $result->addListener(PHPUnit2_Util_TestDox_ResultPrinter::factory('HTML', $testdoxHTMLFile));
         }
         if ($testdoxTextFile !== FALSE) {
             $result->addListener(PHPUnit2_Util_TestDox_ResultPrinter::factory('Text', $testdoxTextFile));
         }
     }
     if ($xmlLogfile !== FALSE) {
         require_once 'PHPUnit2/Util/Log/XML.php';
         $result->addListener(new PHPUnit2_Util_Log_XML($xmlLogfile));
     }
     if ($coverageDataFile !== FALSE || $coverageHTMLFile !== FALSE || $coverageTextFile !== FALSE) {
         $result->collectCodeCoverageInformation(TRUE);
     }
     $timer->start();
     $suite->run($result);
     $timer->stop();
     $timeElapsed = $timer->timeElapsed();
     $this->pause($wait);
     $this->printer->printResult($result, $timeElapsed);
     $this->handleCodeCoverageInformation($result, $coverageDataFile, $coverageHTMLFile, $coverageTextFile);
     return $result;
 }
Exemple #11
0
 /**
  * Perform mySQL query and try to determine result value
  *
  * @param string $query
  * @param string $output
  * @param string $index_field    if set, the resulting array will have the value
  *                               of the $index_field as a key
  *                               (use with caution if a get_row() call will follow!)
  * @return bool|int
  */
 public function query($query, $output = OBJECT, $index_field = null)
 {
     global $MODULE_VARS;
     // Keep track of the time the query took?
     $sql_time = is_array($MODULE_VARS['default']) && array_key_exists('NC_DEBUG_SQL_TIME', $MODULE_VARS['default']) && $MODULE_VARS['default']['NC_DEBUG_SQL_TIME'];
     // Keep track of from where the method was executed?
     $sql_func = is_array($MODULE_VARS['default']) && array_key_exists('NC_DEBUG_SQL_FUNC', $MODULE_VARS['default']) && $MODULE_VARS['default']['NC_DEBUG_SQL_FUNC'];
     if ($sql_time && !class_exists('Benchmark_Timer')) {
         require_once "Benchmark/Timer.php";
     }
     if ($this->benchmark || $sql_time) {
         $timer = new Benchmark_Timer();
         $timer->start();
     }
     // For reg expressions
     $query = trim($query);
     // Initialise return
     $return_val = 0;
     $this->is_error = 0;
     $func = '';
     $this->errno = 0;
     // Flush cached values..
     $this->flush();
     // Log how the function was called
     //        $this->func_call = "\$db->query(\"$query\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Perform the query via std mysql_query function..
     $this->result = @mysql_query($query, $this->dbh);
     $this->num_queries++;
     $q = ['query' => $query];
     // таймер
     if ($this->benchmark || $sql_time) {
         $timer->stop();
         if ($this->benchmark) {
             $timer->display();
         }
         $sql_time = $timer->timeElapsed();
         $q['sql_time'] = $sql_time;
     }
     if ($sql_func) {
         $backtrace = debug_backtrace();
         $func = ($backtrace[2]['class'] ? $backtrace[2]['class'] . '::' : '') . $backtrace[2]['function'];
         $q['sql_func'] = $func;
     }
     $this->queries_arr[] = $q;
     // If there is an error then take note of it..
     if ($str = @mysql_error($this->dbh)) {
         $this->register_error($str);
         $this->is_error = 1;
         $this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
         $this->errno = mysql_errno();
         if ($this->debug_all || $this->trace) {
             echo "<div style='border: 2pt solid red; margin: 10px; padding:10px; font-size:13px; color:black;'><br/>\n";
             echo "Query: <b>" . $query . "</b><br/>\n";
             echo "Error: <b>" . $str . "</b><br/>\n";
             echo "</div>\n";
         }
     }
     $this->debugMessage($this->num_queries . ". " . $query, $func, $sql_time, $this->is_error ? 'error' : 'ok');
     if ($this->is_error) {
         return false;
     }
     // Query was an insert, delete, update, replace
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @mysql_affected_rows($this->dbh);
         // Take note of the insert_id
         // NB: не нужно заменять на nc_preg_match(), поскольку запрос не обязательно
         // является корректной UTF строкой - в этом случае условие не будет выполнено!
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $this->insert_id = @mysql_insert_id($this->dbh);
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         if ($this->fill_col_info) {
             $this->col_info = array();
             $i = 0;
             while ($i < @mysql_num_fields($this->result)) {
                 $this->col_info[$i] = @mysql_fetch_field($this->result);
                 $i++;
             }
         } else {
             $this->col_info = false;
         }
         // mysql_query returns TRUE for INSERT/UPDATE/DROP queries and FALSE on error
         if (!is_bool($this->result)) {
             // Store Query Results
             $this->result_output_type = $output;
             if ($output == ARRAY_N) {
                 $fetch_function = 'mysql_fetch_row';
             } elseif ($output == ARRAY_A) {
                 $fetch_function = 'mysql_fetch_assoc';
             } else {
                 $fetch_function = 'mysql_fetch_object';
             }
             // Store results as an objects within main array
             $num_rows = 0;
             while ($row = $fetch_function($this->result)) {
                 $key = $index_field !== null ? is_array($row) ? $row[$index_field] : $row->{$index_field} : $num_rows;
                 $this->last_result[$key] = $row;
                 $num_rows++;
             }
             mysql_free_result($this->result);
             // Log number of rows the query returned
             $this->num_rows = $num_rows;
         }
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     if (1 || $this->debug_all) {
         preg_match("/(from\\s+\\w+)/si", $query, $regs);
         $from = preg_replace("/\\s+/s", " ", $regs[1]);
         $from = preg_replace("/from /i", "FROM ", $from);
         $this->groupped_queries[$from][$this->num_queries] = $query;
     }
     if ($this->benchmark && $GLOBALS["nccttimer"] instanceof Benchmark_Timer) {
         $GLOBALS["nccttimer"]->setMarker("QRY {$this->num_queries}<br />");
     }
     return $return_val;
 }
$db_type = $_SERVER['argv'][1];
// db select is contained with bmark_connect
if (strlen($db_type) <= 0) {
    $db_type = 'drizzle';
}
// phpinfo(); die();
// use software partition
$timer = new Benchmark_Timer();
$timer->start();
$login = '******';
$dao = new Dao($db_type, 'db.yaml');
$dao->connect();
$dao->find('users', 'login', $login, '=');
$dao->close();
$timer->setMarker('Test_Code_Partition');
echo "Elapsed time between Start and Test_Code_Partition: " . $timer->timeElapsed('Start', 'Test_Code_Partition') . "\n";
// use backend partition
$dao2 = new Dao($db_type, 'db.yaml');
$dao2->connect();
$dao2->find('users', 'login', $login, '=', 'mysql');
$dao2->close();
$timer->setMarker('DB_Partition');
echo "Elapsed time between Test_Code_Partition and DB_Partition: " . $timer->timeElapsed('Test_Code_Partition', 'DB_Partition') . "\n";
// use no partition
$dao3 = new Dao($db_type, 'db.yaml');
$dao3->connect();
$dao3->find('users', 'login', $login, '=', 'nopart');
$dao3->close();
$timer->setMarker('No_Partition');
echo "Elapsed time between DB_Partition and No_Partition: " . $timer->timeElapsed('DB_Partition', 'No_Partition') . "\n";
$timer->stop();
Exemple #13
0
 /**
  * Runs a test suite.
  *
  * @param           PHPUnit_Framework_Test $suite
  * @param  optional boolean                $wait
  * @return PHPUnit_Framework_TestResult
  * @access public
  */
 public function doRun(PHPUnit_Framework_Test $suite, $wait = false)
 {
     printf("PHPUnit %s by Sebastian Bergmann.\n\n", PHPUnit_Framework_Version);
     $result = new PHPUnit_Framework_TestResult();
     $result->addListener($this->fPrinter);
     $timer = new Benchmark_Timer();
     $timer->start();
     $suite->run($result);
     $timer->stop();
     $this->pause($wait);
     $this->fPrinter->printResult($result, $timer->timeElapsed());
     return $result;
 }