-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1560f4b
Showing
501 changed files
with
65,753 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
How works the benchmark? | ||
----------------------- | ||
|
||
|
||
1.) Add your database login details to the "library/conf.db.php" file (make sure the user has permission to create tables). | ||
|
||
2.) Run the "test.php" file. Once it's completed, the results will be saved as CSV files in the "csv" folder. | ||
|
||
3.) To draw the results you need the Charts class, which is not released open source with this package. | ||
|
||
4.) To add more engines to the test, upload the engine to the "template_engines" folder and re-create the "assign" and "loop" tests. | ||
Check out the 'php' engine for a simple example of what is required. Then add your engine to the "library/config.php" file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
execution_time,anetple,dwoo,haanga,php,raintpl,savant,smarty,twig | ||
1,1196,20774,29197,514,5482,2593,13343,9038 | ||
10,1069,16747,28449,540,5720,2713,9662,7010 | ||
20,1079,18114,29163,537,6102,2676,9362,6203 | ||
50,1113,17820,28131,533,6014,2646,9339,6661 | ||
100,1260,18044,28103,561,5734,2916,9961,6301 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
memory,anetple,dwoo,haanga,php,raintpl,savant,smarty,twig | ||
1,77,1776,2500,12,279,186,1623,903 | ||
10,75,1778,2500,12,280,187,1293,718 | ||
20,76,1780,2500,12,281,188,1297,716 | ||
50,79,1786,2500,12,284,191,1318,716 | ||
100,84,1795,2500,12,289,196,1351,716 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
execution_time,anetple,dwoo,haanga,php,raintpl,savant,smarty,twig | ||
1,1713,18269,22057,501,5132,2801,11947,8581 | ||
10,1336,18289,22092,474,5059,2676,9596,6831 | ||
20,1113,18976,20986,571,4541,2718,9667,6891 | ||
50,1145,18717,21387,639,5065,2573,9444,8473 | ||
100,1389,18776,22226,870,5147,2993,9915,10050 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
memory,anetple,dwoo,haanga,php,raintpl,savant,smarty,twig | ||
1,77,1828,2489,12,280,187,1624,885 | ||
10,82,1835,2497,19,287,195,1292,704 | ||
20,90,1843,2505,28,295,204,1298,711 | ||
50,114,1867,2530,52,319,231,1323,735 | ||
100,154,1908,2572,92,360,276,1363,776 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The charts library is part of the <a href="http://www.rainframework.com">RainFramework</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The charts library is part of the <a href="http://www.rainframework.com">RainFramework</a>! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
html,body{font-family:"Lucida Grande", "Lucida Sans", Helvetica;font-size:13px;color:#444;} | ||
a:link, a:visited, a:active{color:#333;} | ||
a:hover{color:#ff0000;} | ||
img{border:0px;} | ||
h1{color:#339933;font-family:Georgia, Times;font-size:28px;margin:0px;font-weight:normal;margin-bottom:5px;text-align:center;} | ||
h2{color:#336699;font-family:Georgia, Times;font-size:20px;margin:0px;font-weight:normal;margin-bottom:5px;} | ||
h3{color:#999;font-weight:normal;font-size:13px;text-align:center;} | ||
|
||
.comment{color:#999;} | ||
.graph table{background:#ccc;width:700px;} | ||
.graph td{background:#fff;padding:8px;font-size:13px;} | ||
.graph .table_title{background:#eee;font-weight:bold;} | ||
|
||
form{margin:0px;} | ||
#selector{ background:#def; border:1px solid #cde;padding:20px;margin-bottom:50px;} | ||
#selector input[type=submit]{border:1px solid #ccc;background:#eee;color:#333;text-shadow:1px 1px 1px #fff; padding:5px 10px;cursor:pointer;} | ||
#selector input[type=submit]:hover{background:#cdf;color:#333;text-shadow:0px 0px 0px;border:1px solid #69c;} | ||
|
||
|
||
#wrapper{width:900px;text-align:left;margin:30px auto;} | ||
|
||
.graph{ text-align:left;margin-bottom:100px;} | ||
|
||
.graph_inner{ padding:10px;overflow:hidden; margin-bottom:50px} | ||
.graph h1{padding:10px;margin-bottom:1px;} | ||
|
||
#last_update{position:absolute;top:10px;left:10px;color:#999;font-size:11px} | ||
#social{font-size:11px;color:#999;float:left;margin-bottom:10px;} | ||
#social div{margin:5px;float: left;} | ||
#copyright{font-size:11px;color:#999;float:right;} | ||
#copyright a{font-size:11px;color:#999;float:right;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
<?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(); | ||
|
||
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/mysql.class.php"; | ||
require_once "library/functions.php"; | ||
require_once "library/config.php"; | ||
|
||
$db = new mysql; | ||
$db->connect() or die("db connection error"); | ||
|
||
$test = get('test')=='loop'?'loop':'assign'; | ||
|
||
$summary = $db->get_list( "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" ); | ||
|
||
$last_update = $db->get_field( "time", "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 ); | ||
|
||
$db = new mysql; | ||
$db->connect() or die("db connection error"); | ||
$template_tested = (array) $db->get_list( "SELECT template_engine FROM template_benchmark WHERE test='$test' GROUP BY template_engine ORDER BY template_engine", "template_engine", "template_engine" ); | ||
|
||
if( $template_selected = get( 'template' ) ){ | ||
$where = "WHERE test='$test' AND ("; | ||
$i=0; | ||
foreach( $template_selected as $tpl => $on ){ | ||
$where .= $i==0?" template_engine='$tpl'":" OR template_engine='$tpl'"; | ||
$i=1; | ||
} | ||
$where .= ")"; | ||
} | ||
else | ||
$where = "WHERE test='$test'"; | ||
|
||
|
||
$rows = $db->get_list( "SELECT template_engine, n, avg(execution_time) AS execution_time, avg(memory) AS memory FROM template_benchmark $where GROUP BY template_engine, n ORDER BY n, execution_time, template_engine" ); | ||
$template_show = $db->get_list( "SELECT template_engine, avg(execution_time) AS execution_time FROM template_benchmark $where GROUP BY template_engine ORDER BY n, execution_time, template_engine", "template_engine", "template_engine" ); | ||
$nrows = $db->get_list( "SELECT n FROM template_benchmark $where GROUP BY n" ); | ||
|
||
|
||
?> | ||
|
||
<html> | ||
<head> | ||
<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="wrapper"> | ||
|
||
<h1>PHP Template Engine Comparison</h1> | ||
<h3>speed matter ... 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/> | ||
<a href="http://www.phpcomparison.net/benchmark.zip">click here to download this benchmark</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="graph2" 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 name="social"></a> | ||
Share it if you like it!<br/><br/> | ||
</div> | ||
|
||
<div id="copyright"> | ||
<a href="http://www.federicoulfo.it">Federico Ulfo</a> | ||
</div> | ||
|
||
|
||
|
||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
class Benchmark{ | ||
|
||
private $bench_class; | ||
|
||
public function Benchmark( $bench_class ){ | ||
require_once 'benchmark/' . $bench_class . ".php"; | ||
$this->bench_class = $bench_class; | ||
} | ||
|
||
/** | ||
* Run the benchmark | ||
* @param int Minimum number of iterations | ||
* @param int Maximum number of iterations | ||
* @param int Amount to increment by on each test. | ||
*/ | ||
public function run_template_assign(){ | ||
|
||
$db = sqlite_open('mysqlitedb', 0666, $sqliteerror); | ||
|
||
global $n; | ||
$class = new $this->bench_class; | ||
$methods = get_class_methods( $this->bench_class ); | ||
$h = ''; | ||
// Now let's do all the methods | ||
|
||
|
||
foreach ($methods as $method){ | ||
$h .= $method . ','; | ||
$start = microtime(true); | ||
$class->$method(); | ||
$exc = floor((microtime(true) - $start) * 1000); | ||
sqlite_query($db, "INSERT INTO template_assign ('$method',$n,$exc)" ); | ||
} | ||
return $h; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
$db['default']['dbserver'] = "mysql"; | ||
$db['default']['hostname'] = "localhost"; | ||
$db['default']['username'] = "root"; | ||
$db['default']['password'] = "root"; | ||
$db['default']['database'] = "benchmark"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
#------------------------------------ | ||
# Configuration | ||
#------------------------------------ | ||
|
||
global $template_list_package_size, $template_website; | ||
|
||
// number of execution test for each template | ||
$n_test_for_template = 10; | ||
|
||
// number of variables assigned in each test | ||
$n_values = array( 1, 10, 20, 50, 100 ); | ||
|
||
// get the list of the templates | ||
$template_list = array( | ||
//'anetple', | ||
//'haanga', | ||
//'savant', | ||
//'dwoo', | ||
'raintpl', | ||
'php', | ||
'smarty', | ||
'twig', | ||
); | ||
|
||
$template_list_version = array( | ||
'anetple' => '1.0', | ||
'haanga' => '1.0.4', | ||
'savant' => '3.0.1', | ||
'php' => phpversion(), | ||
'raintpl' => '2.7.0', | ||
'dwoo' => '1.1.1', | ||
'smarty' => '3.1.7', | ||
'twig' => '1.5.1', | ||
); | ||
$template_list_package_size = array( | ||
'anetple' => '16 KB', | ||
'haanga' => '532 KB', | ||
'savant' => '209 KB', | ||
'php' => '4 KB', | ||
'raintpl' => '37 KB', | ||
'dwoo' => '848 KB', | ||
'smarty' => '971 KB', | ||
'twig' => '647 KB', | ||
); | ||
|
||
$template_website = array( | ||
'anetple' => '', | ||
'haanga' => 'http://haanga.org', | ||
'savant' => 'http://phpsavant.com', | ||
'php' => 'http://php.net', | ||
'raintpl' => 'http://www.raintpl.com', | ||
'dwoo' => 'http://dwoo.org', | ||
'smarty' => 'http://www.smarty.com', | ||
'twig' => 'http://twig-project.org', | ||
); |
Oops, something went wrong.