From 7c723068f5f23f71ad51719354799fff42e2f1f3 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Thu, 27 Dec 2012 19:52:51 +0100 Subject: [PATCH] added execution-time measurement --- includes/kernel.php | 7 ++++++- includes/utilities.php | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/includes/kernel.php b/includes/kernel.php index 5fa72cee..f82b9640 100644 --- a/includes/kernel.php +++ b/includes/kernel.php @@ -9,7 +9,7 @@ ini_set('serialize_precision', 4); require('includes/defines.php'); require('config/config.php'); -$e = $AoWoWconf['debug'] === true ? (E_ALL & ~(E_DEPRECATED|E_USER_DEPRECATED|E_STRICT)) : 0; +$e = !!$AoWoWconf['debug'] ? (E_ALL & ~(E_DEPRECATED|E_USER_DEPRECATED|E_STRICT)) : 0; error_reporting($e); require('includes/Smarty-2.6.26/libs/Smarty.class.php'); // Libraray: http://www.smarty.net/ @@ -18,6 +18,9 @@ require('includes/utilities.php'); require('includes/class.user.php'); require('includes/class.database.php'); +// debug: measure execution times +Util::execTime(!!$AoWoWconf['debug']); + // Setup Smarty class Smarty_AoWoW extends Smarty { @@ -141,6 +144,8 @@ if (isset($_COOKIE[COOKIE_AUTH])) else User::init(0); +User::setLocale(); + // assign lang/locale, userdata, characters and custom profiles User::assignUserToTemplate($smarty, true); diff --git a/includes/utilities.php b/includes/utilities.php index 3577d5f2..2d0e62ba 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -233,6 +233,23 @@ class Util 'large' => 'style="background-image: url(/images/icons/large/%s.jpg)"', ); + private static $execTime = 0.0; + + public static function execTime($set = false) + { + if ($set) + { + self::$execTime = microTime(true); + return; + } + + $newTime = microTime(true); + $tDiff = $newTime - self::$execTime; + self::$execTime = $newTime; + + return self::formatTime($tDiff * 1000, true); + } + public static function colorByRarity($idx) { if (!isset(self::$rarityColorStings)) @@ -293,8 +310,8 @@ class Util $sec -= $time['s']; } - if ($sec % 1) - $time['ms'] = $sec * 1000; + if (($sec * 1000) % 1000) + $time['ms'] = (int)($sec * 1000); return $time; } @@ -328,7 +345,7 @@ class Util if (isset($s['s'])) $fmt[] = $s['s']." ".Lang::$main['seconds']; if (isset($s['ms'])) - $fmt[] = $s['ms']." ".Lang::$main['milliseconds']; + $fmt[] = $s['ms']." ".Lang::$main['millisecs']; } return implode(' ', $fmt);