function speedTrackExecuteQuery($query) { global $mysqlSpeedString, $swMysqlSum, $mysqlSlowQuery; global $printMysqlSpeedString; if (!isset($mysqlSpeedString)) { $mysqlSpeedString = ""; } if (!isset($printMysqlSpeedString)) { $printMysqlSpeedString = FALSE; } if (!isset($swMysqlSum)) { $swMysqlSum = 0; } if (!isset($mysqlSlowQuery)) { $mysqlSlowQuery = 1.0; } $sw = new Stopwatch(); $sw->start(); $result = mysql_query($query); $sw->stop(); $ela = $sw->elapsed(); $hh = (double) $sw->elapsed(); $swMysqlSum += $hh; if ($hh > $mysqlSlowQuery) { $ela = "<font color='red'>{$ela}</font>"; } if ($printMysqlSpeedString) { $mysqlSpeedString .= "<br>{$query} - <b>{$ela}</b>"; } if (class_exists("mysqlspeed")) { writeMysqlSpeedRecord($query, $hh); } return $result; }
/** * Timer start * * @param string $methodName Method name * @return StopwatchEvent */ protected function _getStopwatchEvent($methodName) { $tags = array('group' => 'orm::' . $methodName); if ($this->_serverName) { $tags['server'] = $this->_serverName; } return $this->_stopwatch->start($tags); }
/** * Adds the stopwatch into the manager * * @param Stopwatch $stopwatch * @throws StopwatchAlreadyExistsException */ public function addStopwatch(Stopwatch $stopwatch) { $name = $stopwatch->getName(); if (isset($this->stopwatches[$name])) { throw new StopwatchAlreadyExistsException(sprintf('The stopwatch with name "%s" already exists.', $name)); } $this->stopwatches[$name] = $stopwatch; }
/** * Timer start * * @param string $methodName Method name * @return StopwatchEvent */ protected function _getStopwatchEvent($methodName) { $tags = $this->_stopwatchAdditionalTags; $tags['group'] = 'memcached::' . $methodName; if ($this->_serverName) { $tags['server'] = $this->_serverName; } return $this->_stopwatch->start($tags); }
function initializeSystemSettings() { global $dbHost, $dbUser, $dbUserPw, $dbName, $includeDumpJs; global $gorumroll, $speedStopWatch, $gorumview, $jQueryLib; $_GET = filterInput($_GET); $_COOKIE = filterInput($_COOKIE); $_SERVER = filterInput($_SERVER); $_FILES = filterInput($_FILES); if (class_exists("speedstat")) { $speedStopWatch = new Stopwatch(); $speedStopWatch->start(); } ini_set("session.use_cookies", 1); ini_set("session.use_only_cookies", 1); ini_set("session.use_trans_sid", 0); if (!session_id()) { session_start(); } $this->kbfu = chr(103) . chr(111) . chr(114) . chr(117) . chr(109) . chr(117) . chr(115) . chr(101) . chr(114); $this->kbfk = chr(105) . chr(115) . chr(65) . chr(100) . chr(109); $this->kbfr = chr(103) . chr(111) . chr(114) . chr(117) . chr(109) . chr(114) . chr(101) . chr(99) . chr(111) . chr(103) . chr(110) . chr(105) . chr(115) . chr(101) . chr(100); // http://hu.php.net/manual/en/reserved.variables.session.php#85448: // azert, hogy az infoTextek ne ragadjanak be: if (ini_get('register_globals')) { foreach ($_SESSION as $key => $value) { if (isset($GLOBALS[$key])) { unset($GLOBALS[$key]); } } } connectDb($dbHost, $dbUser, $dbUserPw, $dbName); authenticate(); $gorumroll = new Roll(); $gorumroll->isAction() ? include GORUM_DIR . "/gorum_action.php" : (include GORUM_DIR . "/gorum_view.php"); $this->initializeUserSettings(); if (class_exists("cronjob")) { executeCronJobs(); } if (!$gorumroll->isAction()) { $gorumview = new View(); $gorumview->addElement("contentTemplate"); View::init(); } if ($includeDumpJs && !$gorumroll->isAction()) { JavaScript::addInclude(GORUM_JS_DIR . $jQueryLib); JavaScript::addInclude(GORUM_JS_DIR . "/jquery/jquery.dump.js"); JavaScript::addInclude(GORUM_JS_DIR . "/dump.js"); } $this->kbf(); }
public function testElapsedStepsWithPause() { $this->stopWatch->start(); usleep(2500); $this->stopWatch->pause(); usleep(32000); $this->stopWatch->step('step1'); usleep(32000); $this->stopWatch->resume(); usleep(4000); $this->stopWatch->pause(); usleep(32000); $this->stopWatch->resume(); usleep(4000); $this->stopWatch->step('step2'); usleep(8000); $this->stopWatch->pause(); usleep(32000); $this->stopWatch->step('step3'); usleep(32000); $this->stopWatch->stop(); $elapsedSteps = $this->stopWatch->getElapsedStepsMilliseconds(); $this->assertCount(3, $elapsedSteps); $this->assertArrayHasKey('step1', $elapsedSteps); $this->assertArrayHasKey('step2', $elapsedSteps); $this->assertArrayHasKey('step3', $elapsedSteps); $this->assertGreaterThanOrEqual(2, $elapsedSteps['step1']); $this->assertLessThan(10, $elapsedSteps['step1']); $this->assertGreaterThanOrEqual(10, $elapsedSteps['step2']); $this->assertLessThan(18, $elapsedSteps['step2']); $this->assertGreaterThanOrEqual(18, $elapsedSteps['step3']); $this->assertLessThan(26, $elapsedSteps['step3']); }
/** * Encodes data * @param any $data Data to output * @param string $output Custom output to render. Defaults defined. * @param bool $cached Returns cached status. * @return string Encoded string */ public static function encode($data, $output = DEFAULT_OUTPUT, $cached = FALSE) { self::set_headers($output); $return["status"] = http_response_code(); $return["elapsed_time"] = 0; if (ENVIRONMENT !== "prod") { $return["cached"] = $cached; } $return["data"] = $data; if (class_exists("Stopwatch")) { Stopwatch::stop(); $return["elapsed_time"] = Stopwatch::get_elapse(); } switch ($output) { case "json": return json_encode($return); case "xml": $output = '<?xml version="1.0" encoding="UTF-8"?><response>'; $output .= self::XML_encode($return); $output .= '</response>'; return $output; default: throw new APIexception("Output not supported", 7, 400); } }
/** * Start a timer. * * @param string $name The name of the timer to start * @param string $group Name of the group timer * @param string $operation Method name * @param string $server Server name * @param array $additionalTags Additional tags * * @return bool */ public static function start($name, $group, $operation, $server = '', $additionalTags = array()) { if (empty($name)) { return false; } $stopwatch = Stopwatch::getInstance(); $tags = $additionalTags; $tags['group'] = $group . '::' . $operation; if ($server != '') { $tags['server'] = $server; } if (isset(self::$_timers[$name])) { self::stop($name); } self::$_timers[$name] = $stopwatch->start($tags); return true; }
} } return $data; } return htmlentities($data); } } //Class autoloader function engineAutoload($class) { if (file_exists("engine/" . $class . ".class.php")) { require_once "engine/" . $class . ".class.php"; } } // Register Class Autoloader spl_autoload_register('engineAutoload'); //Load API try { // Composer autoloader if (!file_exists("vendor/autoload.php")) { throw new APIexception("Composer not updated. Please update Composer in order to proceed."); } require 'vendor/autoload.php'; //Init measure time Stopwatch::start(); $API = new APIhandler(); echo $API->endpoint_process(); //echo $API->endpoint_info(); } catch (APIexception $e) { echo $e->output(); }
<?php namespace Jacere; define('APP_PATH', __DIR__); define('LIB_TEST_PATH', APP_PATH . '/../test/lib'); define('LIB_SUBVERT_PATH', APP_PATH . '/..'); define('LIB_SKHEMA_PATH', LIB_SUBVERT_PATH . '/../skhema'); define('LIB_BRAMBLE_PATH', LIB_SUBVERT_PATH . '/../bramble'); define('TEST_DISPLAY', false); define('TEST_ITERATIONS', 1); require_once LIB_SKHEMA_PATH . '/Stopwatch.php'; $sw = Stopwatch::StartNew(sprintf('Subvert: %d iteration(s)', TEST_ITERATIONS)); require_once LIB_SUBVERT_PATH . '/Subvert.php'; require_once LIB_SKHEMA_PATH . '/Template.php'; require_once LIB_TEST_PATH . '/Parsedown/Parsedown.php'; require_once LIB_TEST_PATH . '/PHPMarkdownLib/Michelf/Markdown.php'; require_once LIB_TEST_PATH . '/PHPMarkdownLib/Michelf/MarkdownExtra.php'; function GetTestFiles($file_patterns) { $file_groups = []; foreach ($file_patterns as $key => $pattern) { $file_groups[$key] = glob($pattern); } foreach ($file_groups as $key => &$files) { if (count($files) > 1) { $contents = []; $hash = md5($file_patterns['subvert']); $tmp = APP_PATH . '/.tmp.' . $hash; foreach ($files as $file) { $title = pathinfo($file, PATHINFO_FILENAME);
<?php $relPath = "./../../pinc/"; include_once $relPath . 'base.inc'; include_once $relPath . 'wordcheck_engine.inc'; include_once $relPath . 'slim_header.inc'; include_once $relPath . 'misc.inc'; // attr_safe() include_once $relPath . 'Stopwatch.inc'; include_once './post_files.inc'; include_once "./word_freq_table.inc"; require_login(); $datetime_format = _("%A, %B %e, %Y at %X"); $watch = new Stopwatch(); $watch->start(); set_time_limit(0); // no time limit $freqCutoff = get_integer_param($_REQUEST, 'freqCutoff', 5, 0, null); $timeCutoff = get_integer_param($_REQUEST, 'timeCutoff', -1, -1, null); // load the PM $pm = array_get($_REQUEST, "pm", $pguser); if (!user_is_a_sitemanager() && !user_is_proj_facilitator()) { $pm = $pguser; } // $frame determines which frame we're operating from // none - we're the master frame // 'left' - we're the left frame with the text // 'right' - we're the right frame for the context info // 'update' - not a frame at all - process the incoming data $frame = get_enumerated_param($_REQUEST, 'frame', 'master', array('master', 'left', 'right', 'update')); if ($frame == "update") {
<?php /** * Dieses Script einfach in einer CLI ausführen * Ein Webserver ist nicht notwendig. * * Dieses Script demonstriert die Basisfunktionen und * fuehrt einige Benchmarks durch. */ include __DIR__ . "/examples-utils.php"; // Lambda classes use PerrysLambda\ObjectArray as OA; use PerrysLambda\ArrayList as AL; // Stopwatch $total = new Stopwatch(); $watch = new Stopwatch(); $total->start(); // Memory usage on start echo "\n"; L::line("Begin."); // Basic example $watch->start(); $test = new AL(array(1, 2, 3, 4, 5, 6, 7, 8, 9)); L::vdl($test->where(function ($v) { return $v > 5; })->toArray()); L::line("Select values greater than X from simple array", $watch->stop()->result()); echo "\n"; // Parse JSON (testdata) L::line("Filesize of JSON is", number_format(filesize(__DIR__ . "/testdata.json") / 1024, 2), "KB"); $watch->start();
if (Request::IsPost()) { if (!validate()) { $TEMPLATE['data'] = $_POST; } else { // 首先获取内容中包含的远程图片,并替换为本地图片 $content = save_remote_img($_POST['content']); $wbs = $_POST['target']; $task = new Task(); if ($_POST['time'] == 'on') { // 定时发送 foreach ($wbs as $type) { $task->AddTask($type, $content, $_POST['send_time'], NULL, Task::TASK, NULL, 'blog', $_POST['title']); } $TEMPLATE['report']['time'] = array('status' => true, 'msg' => '定时发送成功!<a href="task.php">查看</a>'); } else { $watch = new Stopwatch(); $watch->Start(); // 直接发送 foreach ($wbs as $type) { $type_arr = explode('|', $type); $third = $thirdAccount->getByType($type_arr[0], $type_arr[1]); $api = Factory::CreateAPI2($type_arr[0], $type_arr[1], $third); $ret = $api->publish($_POST['title'], $content); if ($ret !== true && str_contains($ret, '已过期')) { $thirdAccount->fail($third, $ret); } $TEMPLATE['report'][$type] = array('status' => $ret === true, 'msg' => $ret === true ? '发送成功!' . ($third['url'] ? '<a href="' . $third['url'] . '" target="_blank">查看</a>' : '') : '发送失败:' . $ret . ' <a href="list_err.php">重新发送</a>'); $task->AddTask($type, $content, time(), NULL, $ret === true ? Task::OK : Task::ERROR, $ret, 'blog', $_POST['title']); } $watch->Stop(); $TEMPLATE['report']['watch'] = array('status' => true, 'msg' => "总耗时:{$watch->getElapsedSeconds()} 秒");
/** * 执行定时发送任务脚本,需用crontab执行 * @author 潘洪学 panliu888@gmail.com * @create_date 2011-10 */ include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; // test curl $curl = curl_init(); curl_close($curl); // 设置执行超时时间(秒) set_time_limit(500); // 更新脚本最后执行时间 $user = new User(); $user->update(array('last_exec' => time()), array()); $watch = new Stopwatch(); $watch->Start(); $task = new Task(); $tasks = $task->GetExecTasks(); $taskIds = array_keys($tasks); $task->UpdateStatus(Task::EXECING, $taskIds); $thirdAccount = new ThirdAccount(); foreach ($tasks as $id => $item) { $type_arr = explode('|', $item['type']); if (str_contains($item['msg'], '验证码') || str_contains($item['msg'], 'valCodeError') || $type_arr[0] == 'qzone_simula') { if (time() - $item['last_send'] < 10 * 60) { continue; } } if (str_contains($item['msg'], '重复发送') || str_contains($item['msg'], '用户调用次数超过限制')) { $task->update(array('retry_count' => Task::RETRY_COUNT), array('id' => $id));
/** * {@inheritDoc} */ public function beforeRender($viewFile) { $this->_stopwatchEvent = $this->_stopwatch->start(array('server' => 'localhost', 'group' => 'view::render', 'view_template' => basename($viewFile))); }
/** * {@inheritDoc} */ public function beforeSave(Model $Model, $options = array()) { $this->_stopwatchEventSave = $this->_stopwatch->start(array('server' => $this->_serverName, 'group' => 'orm::save')); return true; }
/** * Stops count */ public static function stop() { self::$stop = array_sum(explode(' ', microtime())); }
public static function time($name) { if ($sw = Stopwatch::instance()) { $sw->save($name); } }
/** * Before render - set up template variables, add helpers... * @return type */ public function beforeRender() { parent::beforeRender(); /** set visibility of newItem form */ $this->canAdd = false; $permissions = $this->getUser()->isLoggedIn() ? $this->getUser()->getIdentity()->getRoles() : NULL; if (isset($permissions[$this->pageUrl]) && $this->pageConfig['settings']['lvlForAdding'] <= $permissions[$this->pageUrl] || $permissions['admin'] || $this->pageConfig['settings']['lvlForAdding'] == 0) { $this->canAdd = true; } $this->template->canAdd = $this->canAdd; $this->template->page = $this->pageConfig; $this->template->pages = $this->pages; $this->template->pageUrl = !empty($this->pageUrl) ? $this->pageUrl : 'default'; $this->template->isAdmin = $this->isAdmin(); $helpers = new \Agility\Helpers(); $this->template->registerHelperLoader(array($helpers, 'loader')); \Stopwatch::stop('BasePresenter'); }
include_once $relPath . 'wordcheck_engine.inc'; include_once $relPath . 'project_states.inc'; include_once $relPath . 'stages.inc'; include_once $relPath . 'LPage.inc'; include_once $relPath . 'Project.inc'; include_once $relPath . 'slim_header.inc'; include_once $relPath . 'misc.inc'; // attr_safe(), html_safe() include_once $relPath . 'Stopwatch.inc'; include_once './post_files.inc'; include_once "./word_freq_table.inc"; require_login(); define("LAYOUT_HORIZ", 1); define("LAYOUT_VERT", 2); $datetime_format = _("%A, %B %e, %Y at %X"); $watch = new Stopwatch(); $watch->start(); set_time_limit(0); // no time limit $projectid = validate_projectID('projectid', @$_REQUEST['projectid']); $encWord = $_GET["word"]; $word = decode_word($encWord); $timeCutoff = get_integer_param($_REQUEST, 'timeCutoff', 0, 0, null); enforce_edit_authorization($projectid); // get the correct layout $default_layout = @$_SESSION["show_good_word_suggestions_detail"]["layout"]; if (is_null($default_layout)) { // The normal case for the session's first visit. $default_layout = LAYOUT_HORIZ; } else { if ($default_layout === LAYOUT_HORIZ || $default_layout === LAYOUT_VERT) {
list($length, $text) = $column; $result .= str_pad($text, $length, " ", STR_PAD_RIGHT); } return $result . "\n"; } // Lambda classes use PerrysLambda\ObjectArray; use PerrysLambda\ArrayList; use PerrysLambda\Serializer; use PerrysLambda\IO\LineIterator; use PerrysLambda\Converter; use PerrysLambda\IO\File; use PerrysLambda\FieldSerializer\DateTime as SerDateTime; // Timer $total = new Stopwatch(); $watch = new Stopwatch(); $total->start(); echo "\n"; L::line("Begin."); $watch->start(); /** * Parser */ // Serialize row to JSON $rowser = function (&$row, &$key) { $row = json_encode(array("sensordata" => $row)); return true; }; // Deserialize JSON String to ObjectArray $rowdeser = function (&$row, &$key) { if (!$row instanceof ObjectArray) {