-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.php
executable file
·231 lines (189 loc) · 8.68 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/**
* Benchmark
* ---------
* This benchmark is realized by Federico Ulfo. The library are part of the RainFramework.
* Distributed under MIT license http://www.opensource.org/licenses/mit-license.php
*/
session_start();
require "vendor/autoload.php";
if(isset($_SESSION['working'])) {
header("Refresh: 30; url=index.php");
echo 'Benchmarking currently in progress. The results will appear here once the test has completed.' . "\n";
exit();
}
require_once "library/functions.php";
require_once "library/config.php";
use Rain\DB;
DB::init();
$test = get('test')=='loop'?'loop':'assign';
$summary = DB::getAll("SELECT template_engine AS name,
avg(execution_time) AS execution_time,
avg(memory) AS memory
FROM template_benchmark
WHERE test=:test
GROUP BY template_engine
ORDER BY execution_time",
array(":test"=>$test)
);
$last_update = DB::getField("SELECT time
FROM template_test_counter
LIMIT 1");
$last_update_date = date( "M d Y", $last_update );
$last_update_time = date( "h:i A", $last_update );
$template_tested = DB::getAll("SELECT template_engine
FROM template_benchmark
WHERE test=:test
GROUP BY template_engine
ORDER BY template_engine",
array(":test"=>$test),
"template_engine",
"template_engine" );
$rows = DB::getAllArray( 'SELECT template_engine,
n,
avg(execution_time) AS execution_time,
avg(memory) AS memory
FROM template_benchmark
WHERE test=:test
GROUP BY template_engine, n
ORDER BY n, execution_time, template_engine',
array(":test"=>$test)
);
$template_show = DB::getAllArray("SELECT template_engine,
avg(execution_time) AS execution_time
FROM template_benchmark
WHERE test=:test
GROUP BY template_engine
ORDER BY n, execution_time, template_engine",
array(':test'=>$test),
"template_engine",
"template_engine");
$nrows = DB::getAllArray( "SELECT n
FROM template_benchmark
WHERE test=:test
GROUP BY n",
array(':test'=>$test));
?>
<html>
<head>
<meta charset="utf-8">
<title>PHP Template Engine Comparison</title>
<link href="graph/style.css" type="text/css" rel="stylesheet"/>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-5639487-17']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="header">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7450782533421767";
/* PHP header */
google_ad_slot = "6883406703";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div id="wrapper">
<h1>PHP Template Engine Comparison</h1>
<h3>Speed matters... sometimes...</h3>
<br/>
<div id="last_update">updated on <?php echo $last_update_date; ?> at <?php echo $last_update_time; ?></div>
<p>
A blogger asked me "Do you know any professional benchmarks for templates?" So I made this one.
Now, this project is getting the attention of the international PHP developers community, which is divided
in two. One says PHP itself is the best template engine, the other says PHP needs template engines.
With these benchmark & charts you can compare the performances of template engines vs PHP templates, and make your choice.
<br/><br/><br/>
This benchmark is performed by executing an assignment and a loop test. Each template engine is executed <?php echo $n_test_for_template; ?> times foreach single test.
The test is executed on compiled template. The charts shows the average execution time and memory consumed for each test. Have fun! <br/>
<br/><br/>
This project is open source <a href="https://github.com/rainphp/phpcomparison" target="_blank">click here to download the benchmark!</a> and <a href="https://twitter.com/feulf" target="_blank">here follow me on Twitter</a>
</p>
<br/><br/>
<div id="selector">
<form action="index.php">
<?php
$sel = "";
foreach( $template_tested as $template ){
if( isset($template_show[ $template ] ))
$sel .= "template[".$template . "]=on&";
echo '<label for="'.$template.'">'.$template.'</label> <input type="checkbox" name="template['.$template.']" '. ( isset($template_show[ $template ]) ? 'checked="checked"':'' ) .'> ';
}
?>
<select name="test"><option value="assign" <?php if($test=='assign')echo 'SELECTED'; ?> >Assign</option><option value="loop" <?php if($test=='loop')echo 'SELECTED'; ?>>Loop</option></select>
<input type="submit" value="Click to refresh">
</form>
</div>
<div class="graph">
<h2>Summary (<?php echo $test; ?>)</h2>
<table cellpadding="0" cellspacing="1">
<tr>
<td class="table_title">Test</td>
<td class="table_title">tot. time</td>
<td class="table_title">tot. memory</td>
<td class="table_title">package size</td>
</tr>
<?php
global $template_website;
foreach( $summary as $name => $res ){
if( isset($template_show[$res['name']]) ){
?>
<tr>
<td><?php echo '<a href="'.($template_website[$res['name']]).'" target="_blank">'.$res['name'] . '</a>'; ?> <span class="comment"><? echo $template_list_version[$res['name']]; ?></span></td>
<td><?php echo msec($res['execution_time']); ?></td>
<td><?php echo format_memory($res['memory']); ?></td>
<td><?php echo getDirectorySize($res['name']); ?></td>
</tr>
<?php } } ?>
</table>
</div>
<div class="graph">
<h2>Execution Time (<?php echo $test; ?>)</h2>
<div class="graph_inner">
<iframe id="graph2" src="graph/line.php?<?php echo $sel; ?>test=<?php echo $test; ?>" width="100%" height="350" style="border:0px;"></iframe>
</div>
<h2>Memory (<?php echo $test; ?>)</h2>
<div class="graph_inner">
<iframe id="graph3" src="graph/line.php?<?php echo $sel; ?>type=memory&test=<?php echo $test; ?>" width="100%" height="350" style="border:0px;"></iframe>
</div>
</div>
<div class="graph">
<h2>Total average (<?php echo $test; ?>)</h2>
<div class="graph_inner">
<div style="float:left;"><iframe src="graph/pie.php?<?php echo $sel; ?>test=<?php echo $test; ?>" width="440" height="380" style="border:0px;"></iframe></div>
<div style="float:right;"><iframe src="graph/pie.php?<?php echo $sel; ?>test=<?php echo $test; ?>&type=memory" width="440" height="380" style="border:0px;"></iframe></div>
</div>
</div>
</div>
<div id="social">
<a href="https://twitter.com/feulf" target="_blank">Follow me on Twitter</a>
<br/><br/>
</div>
<div id="copyright">
<a href="http://www.federicoulfo.it">Federico Ulfo</a>
</div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7450782533421767";
/* PHP Comparison */
google_ad_slot = "8302242302";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</body>
</html>