Take two:
[www-register-wizard.git] / libraries / Benchmark.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
2 /**\r
3  * CodeIgniter\r
4  *\r
5  * An open source application development framework for PHP 4.3.2 or newer\r
6  *\r
7  * @package             CodeIgniter\r
8  * @author              ExpressionEngine Dev Team\r
9  * @copyright   Copyright (c) 2008, EllisLab, Inc.\r
10  * @license             http://codeigniter.com/user_guide/license.html\r
11  * @link                http://codeigniter.com\r
12  * @since               Version 1.0\r
13  * @filesource\r
14  */\r
15 \r
16 // ------------------------------------------------------------------------\r
17 \r
18 /**\r
19  * CodeIgniter Benchmark Class\r
20  *\r
21  * This class enables you to mark points and calculate the time difference\r
22  * between them.  Memory consumption can also be displayed.\r
23  *\r
24  * @package             CodeIgniter\r
25  * @subpackage  Libraries\r
26  * @category    Libraries\r
27  * @author              ExpressionEngine Dev Team\r
28  * @link                http://codeigniter.com/user_guide/libraries/benchmark.html\r
29  */\r
30 class CI_Benchmark {\r
31 \r
32         var $marker = array();\r
33 \r
34         // --------------------------------------------------------------------\r
35 \r
36         /**\r
37          * Set a benchmark marker\r
38          *\r
39          * Multiple calls to this function can be made so that several\r
40          * execution points can be timed\r
41          *\r
42          * @access      public\r
43          * @param       string  $name   name of the marker\r
44          * @return      void\r
45          */\r
46         function mark($name)\r
47         {\r
48                 $this->marker[$name] = microtime();\r
49         }\r
50 \r
51         // --------------------------------------------------------------------\r
52 \r
53         /**\r
54          * Calculates the time difference between two marked points.\r
55          *\r
56          * If the first parameter is empty this function instead returns the\r
57          * {elapsed_time} pseudo-variable. This permits the full system\r
58          * execution time to be shown in a template. The output class will\r
59          * swap the real value for this variable.\r
60          *\r
61          * @access      public\r
62          * @param       string  a particular marked point\r
63          * @param       string  a particular marked point\r
64          * @param       integer the number of decimal places\r
65          * @return      mixed\r
66          */\r
67         function elapsed_time($point1 = '', $point2 = '', $decimals = 4)\r
68         {\r
69                 if ($point1 == '')\r
70                 {\r
71                         return '{elapsed_time}';\r
72                 }\r
73 \r
74                 if ( ! isset($this->marker[$point1]))\r
75                 {\r
76                         return '';\r
77                 }\r
78 \r
79                 if ( ! isset($this->marker[$point2]))\r
80                 {\r
81                         $this->marker[$point2] = microtime();\r
82                 }\r
83         \r
84                 list($sm, $ss) = explode(' ', $this->marker[$point1]);\r
85                 list($em, $es) = explode(' ', $this->marker[$point2]);\r
86 \r
87                 return number_format(($em + $es) - ($sm + $ss), $decimals);\r
88         }\r
89         \r
90         // --------------------------------------------------------------------\r
91 \r
92         /**\r
93          * Memory Usage\r
94          *\r
95          * This function returns the {memory_usage} pseudo-variable.\r
96          * This permits it to be put it anywhere in a template\r
97          * without the memory being calculated until the end.\r
98          * The output class will swap the real value for this variable.\r
99          *\r
100          * @access      public\r
101          * @return      string\r
102          */\r
103         function memory_usage()\r
104         {\r
105                 return '{memory_usage}';\r
106         }\r
107 \r
108 }\r
109 \r
110 // END CI_Benchmark class\r
111 \r
112 /* End of file Benchmark.php */\r
113 /* Location: ./system/libraries/Benchmark.php */