New version submitted by TomB
[carbonphp.git] / Documentation / libraries / benchmark.html
blob2f2eb1c6c119b94bd155587cf442a23355d9586d
1 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2 <head>
3 <title>CarbonPHP Documentation</title>
4 <style type="text/css">
5 * {
6 margin: 0;
7 padding: 0;
10 html {
11 font-family: "Lucida Sans Unicode", "Lucida Grande";
12 font-size: 12px;
15 body {
16 background: #fff;
17 color: #666;
20 h1 {
21 font-size: 15px;
22 font-weight: bold;
23 margin: 0 0 5px 0;
26 h2 {
27 font-size: 13px;
28 font-weight: bold;
29 margin: 5px 0 5px 0;
32 ol, ul {
33 margin: 10px 0 10px 0;
34 list-style-position: inside;
37 p {
38 margin: 5px 0 5px 0;
41 .content {
42 border: 1px dotted #444;
43 margin: 10px;
44 padding: 10px;
45 text-align: justify;
46 width: 700px;
49 .example {
50 border: 1px solid #ccc;
51 background: #eee;
52 margin: 10px;
53 padding: 10px;
55 </style>
56 </head>
58 <body>
59 <div class="content">
60 <h1>Benchmark Library</h1>
62 <p>CarbonPHP has a benchmark library that is always active, this library enables you to make the time
63 between two points. <i>Note</i>: the benchmark library is automatically loaded by CarbonPHP so there is no
64 need for you to load it.</p>
66 <p>The benchmark library is always started the moment the framework is invoked, and ended once the output
67 class is ready to send the final data to the browser. This means a very accurate value for the time the
68 system took to execute.</p>
69 </div>
71 <div class="content">
72 <h1>Using the Benchmark Library</h1>
74 <p>The benchmark library can be used within, models, views, or controllers. The process of using the library
75 is as follows.</p>
77 <ol>
78 <li>Mark the start point.</li>
79 <li>Mark the end point.</li>
80 <li>Run the <b>elapsed_time()</b> function to view the result.</li>
81 </ol>
83 <p>A simple example of using the benchmark library is shown below.</p>
85 <div class="example">
86 $this->benchmark->mark('code_start');<br />
87 <br />
88 // Some code executes here...<br />
89 <br />
90 $this->benchmark->mark('code_end');<br />
91 <br />
92 echo $this->benchmark->elapsed_time('code_start', 'code_end');
93 </div>
95 <p><i>Note</i>: the marker words <b>code_start</b> and <b>code_end</b> can be any words of your choosing.
96 See the follow example.</p>
98 <div class="example">
99 $this->benchmark->mark('cow');<br />
100 <br />
101 // Some code executes here...<br />
102 <br />
103 $this->benchmark->mark('duck');<br />
104 <br />
105 // Some more code executes here...<br />
106 <br />
107 $this->benchmark->mark('sheep');<br />
108 <br />
109 echo $this->benchmark->elapsed_time('cow', 'duck');<br />
110 echo $this->benchmark->elapsed_time('duck', 'sheep');<br />
111 echo $this->benchmark->elapsed_time('cow', 'sheep');
112 </div>
113 </div>
115 <div class="content">
116 <h1>Displaying Total CarbonPHP Execution Time</h1>
118 <p>If you wish to display the total time it took the framework the execute. You can simply place the following
119 method call into your view.</p>
121 <div class="example">
122 &lt;?php echo $this->benchmark->elapsed_time(); ?&gt;
123 </div>
125 <p>You will notice that the above code uses the same method as calculating the time between two mark points,
126 except there are no parameters passed to the method. An alternate way to show the total framework elapsed
127 time is to include the psuedo-variable <b>{elapsed_time}</b> in your view if you do not wish to use the
128 pure PHP code.</p>
130 <div class="example">
131 {elapsed_time}
132 </div>
133 </div>
135 <div class="content">
136 <h1>Displaying CarbonPHP Memory Usage</h1>
138 <p>If your PHP installation is setup with the <b>--enable-memory-limit</b> configuration option, you can
139 display the memory that CarbonPHP is using. To do this you can use the following line of code.</p>
141 <div class="example">
142 &lt;?php echo $this->benchmark->memory_usage(); ?&gt;
143 </div>
145 <p><i>Note</i>: if you wish to use this method, it can only be used in your view files. The memory usage
146 shown by this method will display the amount of memory used by the entire application. You can also use a
147 psuedo-variable to display the memory usage, just like elapsed time.</p>
149 <div class="example">
150 {memory_usage}
151 </div>
152 </div>
153 </body>
155 </html>