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']); }
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; }
/** * 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); } }
/** * 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'); }
/** * Stops count */ public static function stop() { self::$stop = array_sum(explode(' ', microtime())); }
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(); $data = json_decode(file_get_contents(__DIR__ . "/testdata.json"), true); L::line("Loaded data from JSON file.", $watch->stop()->result(), ",", count($data), "records"); // Load JSON data into lambda $watch->start(); $collection = AL::asObjectArray($data); // ArrayList<ObjectArray> L::line("Data imported into Lambda.", $watch->stop()->result(), ",", $collection->length(), "records"); // Unset JSON Data unset($data); L::line("Unset original JSON data."); // where
$row = null; } return false; } return true; }; $conv = new Converter(); $conv->setRowConverter(new Serializer($rowser, $rowdeser)); // Field converters (string to number or datetime) $conv->setFieldConverter('timestamp', new SerDateTime("Y-m-d\\TH:i:s.uO", new \DateTimeZone("Europe/Berlin"))); // Read testdata line by line $iterator = new LineIterator(new File(__DIR__ . "/testdata.txt")); // Load only last 500 records $c = $iterator->count(); $conv->setIteratorSource($iterator); L::line("Converter created:", $watch->stop()->result()); /** * Create list and filter / group */ // Create list $watch->start(); $list = new ArrayList($conv); L::line("Data imported:", $watch->stop()->result()); // Stats echo "\n"; L::line($list->length(), "records"); L::line("First record:", $list->first()->timestamp->format('Y-m-d H:i:s')); L::line("Last record:", $list->last()->timestamp->format('Y-m-d H:i:s')); echo "\n"; // Only the newest day, group by hour $watch->start();