From 979fcceb99e555800fdfbc2cecf4ba585e780b73 Mon Sep 17 00:00:00 2001 From: osmiy Date: Wed, 19 Apr 2006 14:47:21 +0000 Subject: - code optimization (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@2744 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- frontends/php/include/copt.lib.php | 124 +++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 frontends/php/include/copt.lib.php (limited to 'frontends/php/include/copt.lib.php') diff --git a/frontends/php/include/copt.lib.php b/frontends/php/include/copt.lib.php new file mode 100644 index 00000000..aaebaab5 --- /dev/null +++ b/frontends/php/include/copt.lib.php @@ -0,0 +1,124 @@ + 1, "oranges" => 1, "mangoes" => 1, "tomatoes" => 1, "pickles" => 1); + if (isset($keys['mangoes'])) { ... } + + 6)key_exist + if(array_key_exists('mangoes', $keys)) + vs + if (isset($keys['mangoes'])) { ... } + + 7)regexps + POSIX-regexps + vs + Perl-regexps + + 8)constants + UPPER case constans (TRUE, FALSE) + vs + lower case constans (true, false) + + 9)for + for ($i = 0; $i < FUNCTION($j); $i++) {...} + vs + for ($i = 0, $k = FUNCTION($j); $i < $k; $i = $i + 1) {...} + + 10)strings + "var=$var" + vs + 'var='.$var + + */ + + + /* + ** Description: + ** Optimization class. Provide functions for + ** PHP code optimization. + ** + ** Author: + ** Eugene Grigorjev (eugene.grigorjev@zabbix.com) + **/ + + //define("USE_PROFILING",1); + + $starttime[]=array(); + + class COpt + { + /* protected static $starttime[]=array(); */ + + /* protected static */ function getmicrotime() + { + list($usec, $sec) = explode(" ",microtime()); + return ((float)$usec + (float)$sec); + } + /* public static */ function profiling_start($type=NULL) + { + if(!defined('USE_PROFILING')) return; + + global $starttime; + if(is_null($type)) $type="global"; + + $starttime[$type] = COpt::getmicrotime(); + } + /* public static */ function profiling_stop($type=NULL) + { + if(!defined('USE_PROFILING')) return; + + global $starttime; + + $endtime = COpt::getmicrotime(); + + if(is_null($type)) $type="global"; + echo "
\nTime to execute (".$type."): ". bcsub($endtime,$starttime[$type],6)." seconds!\n
"; + } + } + +?> -- cgit