Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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. |
Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @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 Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 34 | * between them. Memory consumption can also be displayed. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * |
| 36 | * @package CodeIgniter |
| 37 | * @subpackage Libraries |
| 38 | * @category Libraries |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 39 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | * @link http://codeigniter.com/user_guide/libraries/benchmark.html |
| 41 | */ |
| 42 | class CI_Benchmark { |
| 43 | |
root | 83e7a8e | 2011-08-14 19:55:57 +0200 | [diff] [blame] | 44 | /** |
| 45 | * List of all benchmark markers and when they were added |
| 46 | * |
| 47 | * @var array |
| 48 | */ |
Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 49 | public $marker = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 59 | * @param string $name name of the marker |
| 60 | * @return void |
| 61 | */ |
Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 62 | public function mark($name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 63 | { |
| 64 | $this->marker[$name] = microtime(); |
| 65 | } |
| 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 77 | * @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 Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 82 | public function elapsed_time($point1 = '', $point2 = '', $decimals = 4) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | { |
| 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 | { |
| 96 | $this->marker[$point2] = microtime(); |
| 97 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 98 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 99 | list($sm, $ss) = explode(' ', $this->marker[$point1]); |
| 100 | list($em, $es) = explode(' ', $this->marker[$point2]); |
| 101 | |
| 102 | return number_format(($em + $es) - ($sm + $ss), $decimals); |
| 103 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 104 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 105 | // -------------------------------------------------------------------- |
| 106 | |
| 107 | /** |
| 108 | * Memory Usage |
| 109 | * |
| 110 | * This function returns the {memory_usage} pseudo-variable. |
| 111 | * This permits it to be put it anywhere in a template |
| 112 | * without the memory being calculated until the end. |
| 113 | * The output class will swap the real value for this variable. |
| 114 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 115 | * @return string |
| 116 | */ |
Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 117 | public function memory_usage() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | { |
| 119 | return '{memory_usage}'; |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 124 | /* End of file Benchmark.php */ |
Andrey Andreev | 2fbbfe3 | 2012-01-07 18:37:15 +0200 | [diff] [blame^] | 125 | /* Location: ./system/core/Benchmark.php */ |