1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
---|
2 | /** |
---|
3 | * CodeIgniter |
---|
4 | * |
---|
5 | * An open source application development framework for PHP 5.1.6 or newer |
---|
6 | * |
---|
7 | * @package CodeIgniter |
---|
8 | * @author ExpressionEngine Dev Team |
---|
9 | * @copyright Copyright (c) 2008 - 2011, 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 | /** |
---|
33 | * List of all benchmark markers and when they were added |
---|
34 | * |
---|
35 | * @var array |
---|
36 | */ |
---|
37 | var $marker = array(); |
---|
38 | |
---|
39 | // -------------------------------------------------------------------- |
---|
40 | |
---|
41 | /** |
---|
42 | * Set a benchmark marker |
---|
43 | * |
---|
44 | * Multiple calls to this function can be made so that several |
---|
45 | * execution points can be timed |
---|
46 | * |
---|
47 | * @access public |
---|
48 | * @param string $name name of the marker |
---|
49 | * @return void |
---|
50 | */ |
---|
51 | function mark($name) |
---|
52 | { |
---|
53 | $this->marker[$name] = microtime(); |
---|
54 | } |
---|
55 | |
---|
56 | // -------------------------------------------------------------------- |
---|
57 | |
---|
58 | /** |
---|
59 | * Calculates the time difference between two marked points. |
---|
60 | * |
---|
61 | * If the first parameter is empty this function instead returns the |
---|
62 | * {elapsed_time} pseudo-variable. This permits the full system |
---|
63 | * execution time to be shown in a template. The output class will |
---|
64 | * swap the real value for this variable. |
---|
65 | * |
---|
66 | * @access public |
---|
67 | * @param string a particular marked point |
---|
68 | * @param string a particular marked point |
---|
69 | * @param integer the number of decimal places |
---|
70 | * @return mixed |
---|
71 | */ |
---|
72 | function elapsed_time($point1 = '', $point2 = '', $decimals = 4) |
---|
73 | { |
---|
74 | if ($point1 == '') |
---|
75 | { |
---|
76 | return '{elapsed_time}'; |
---|
77 | } |
---|
78 | |
---|
79 | if ( ! isset($this->marker[$point1])) |
---|
80 | { |
---|
81 | return ''; |
---|
82 | } |
---|
83 | |
---|
84 | if ( ! isset($this->marker[$point2])) |
---|
85 | { |
---|
86 | $this->marker[$point2] = microtime(); |
---|
87 | } |
---|
88 | |
---|
89 | list($sm, $ss) = explode(' ', $this->marker[$point1]); |
---|
90 | list($em, $es) = explode(' ', $this->marker[$point2]); |
---|
91 | |
---|
92 | return number_format(($em + $es) - ($sm + $ss), $decimals); |
---|
93 | } |
---|
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 | |
---|
113 | } |
---|
114 | |
---|
115 | // END CI_Benchmark class |
---|
116 | |
---|
117 | /* End of file Benchmark.php */ |
---|
118 | /* Location: ./system/core/Benchmark.php */ |
---|