blob: 0f3104079ca70bd46e186f537485a03fed39d764 [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * CodeIgniter Benchmark Class
32 *
33 * This class enables you to mark points and calculate the time difference
Derek Jones4b9c6292011-07-01 17:40:48 -050034 * between them. Memory consumption can also be displayed.
Derek Allard2067d1a2008-11-13 22:59:24 +000035 *
36 * @package CodeIgniter
37 * @subpackage Libraries
38 * @category Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050039 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000040 * @link http://codeigniter.com/user_guide/libraries/benchmark.html
41 */
42class CI_Benchmark {
43
root83e7a8e2011-08-14 19:55:57 +020044 /**
45 * List of all benchmark markers and when they were added
46 *
47 * @var array
48 */
Derek Allard2067d1a2008-11-13 22:59:24 +000049 var $marker = array();
50
51 // --------------------------------------------------------------------
52
53 /**
54 * Set a benchmark marker
55 *
56 * Multiple calls to this function can be made so that several
57 * execution points can be timed
58 *
59 * @access public
60 * @param string $name name of the marker
61 * @return void
62 */
63 function mark($name)
64 {
65 $this->marker[$name] = microtime();
66 }
67
68 // --------------------------------------------------------------------
69
70 /**
71 * Calculates the time difference between two marked points.
72 *
73 * If the first parameter is empty this function instead returns the
74 * {elapsed_time} pseudo-variable. This permits the full system
75 * execution time to be shown in a template. The output class will
76 * swap the real value for this variable.
77 *
78 * @access public
79 * @param string a particular marked point
80 * @param string a particular marked point
81 * @param integer the number of decimal places
82 * @return mixed
83 */
84 function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
85 {
86 if ($point1 == '')
87 {
88 return '{elapsed_time}';
89 }
90
91 if ( ! isset($this->marker[$point1]))
92 {
93 return '';
94 }
95
96 if ( ! isset($this->marker[$point2]))
97 {
98 $this->marker[$point2] = microtime();
99 }
Barry Mienydd671972010-10-04 16:33:58 +0200100
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 list($sm, $ss) = explode(' ', $this->marker[$point1]);
102 list($em, $es) = explode(' ', $this->marker[$point2]);
103
104 return number_format(($em + $es) - ($sm + $ss), $decimals);
105 }
Barry Mienydd671972010-10-04 16:33:58 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 // --------------------------------------------------------------------
108
109 /**
110 * Memory Usage
111 *
112 * This function returns the {memory_usage} pseudo-variable.
113 * This permits it to be put it anywhere in a template
114 * without the memory being calculated until the end.
115 * The output class will swap the real value for this variable.
116 *
117 * @access public
118 * @return string
119 */
120 function memory_usage()
121 {
122 return '{memory_usage}';
123 }
124
125}
126
127// END CI_Benchmark class
128
129/* End of file Benchmark.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600130/* Location: ./system/core/Benchmark.php */