blob: 39027e80979c4fde919c16500afad5a57ce73cc0 [file] [log] [blame]
Andrey Andreev2fbbfe32012-01-07 18:37:15 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev2fbbfe32012-01-07 18:37:15 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev2fbbfe32012-01-07 18:37:15 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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.
Andrey Andreev2fbbfe32012-01-07 18:37:15 +020018 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @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 */
Andrey Andreev2fbbfe32012-01-07 18:37:15 +020049 public $marker = array();
Derek Allard2067d1a2008-11-13 22:59:24 +000050
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 *
Derek Allard2067d1a2008-11-13 22:59:24 +000059 * @param string $name name of the marker
60 * @return void
61 */
Andrey Andreev2fbbfe32012-01-07 18:37:15 +020062 public function mark($name)
Derek Allard2067d1a2008-11-13 22:59:24 +000063 {
dixyab3cab52012-04-21 00:58:00 +020064 $this->marker[$name] = microtime(TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +000065 }
66
67 // --------------------------------------------------------------------
68
69 /**
70 * Calculates the time difference between two marked points.
71 *
72 * If the first parameter is empty this function instead returns the
73 * {elapsed_time} pseudo-variable. This permits the full system
74 * execution time to be shown in a template. The output class will
75 * swap the real value for this variable.
76 *
Derek Allard2067d1a2008-11-13 22:59:24 +000077 * @param string a particular marked point
78 * @param string a particular marked point
79 * @param integer the number of decimal places
80 * @return mixed
81 */
Andrey Andreev2fbbfe32012-01-07 18:37:15 +020082 public function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
Derek Allard2067d1a2008-11-13 22:59:24 +000083 {
84 if ($point1 == '')
85 {
86 return '{elapsed_time}';
87 }
88
89 if ( ! isset($this->marker[$point1]))
90 {
91 return '';
92 }
93
94 if ( ! isset($this->marker[$point2]))
95 {
dixyab3cab52012-04-21 00:58:00 +020096 $this->marker[$point2] = microtime(TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +000097 }
Barry Mienydd671972010-10-04 16:33:58 +020098
dixyab3cab52012-04-21 00:58:00 +020099 return number_format($this->marker[$point2] - $this->marker[$point1], $decimals);
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 }
Barry Mienydd671972010-10-04 16:33:58 +0200101
Derek Allard2067d1a2008-11-13 22:59:24 +0000102 // --------------------------------------------------------------------
103
104 /**
105 * Memory Usage
106 *
107 * This function returns the {memory_usage} pseudo-variable.
108 * This permits it to be put it anywhere in a template
109 * without the memory being calculated until the end.
110 * The output class will swap the real value for this variable.
111 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 * @return string
113 */
Andrey Andreev2fbbfe32012-01-07 18:37:15 +0200114 public function memory_usage()
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 {
116 return '{memory_usage}';
117 }
118
119}
120
Derek Allard2067d1a2008-11-13 22:59:24 +0000121/* End of file Benchmark.php */
dixyab3cab52012-04-21 00:58:00 +0200122/* Location: ./system/core/Benchmark.php */