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