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