mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add benchmark
This commit is contained in:
26
benchmark/run.php
Normal file
26
benchmark/run.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
echo "Smarty3 vs Twig vs Aspect\n\n";
|
||||
|
||||
echo "Generate templates... ";
|
||||
passthru("php ".__DIR__."/templates/inheritance/smarty.gen.php");
|
||||
passthru("php ".__DIR__."/templates/inheritance/twig.gen.php");
|
||||
echo "Done\n";
|
||||
|
||||
echo "Testing large output...\n";
|
||||
passthru("php ".__DIR__."/templates/echo.php");
|
||||
|
||||
echo "\nTesting 'foreach' of big array...\n";
|
||||
passthru("php ".__DIR__."/templates/foreach.php");
|
||||
|
||||
echo "\nTesting deep 'inheritance'...\n";
|
||||
passthru("php ".__DIR__."/templates/inheritance.php");
|
||||
|
||||
echo "\nDone. Cleanup.\n";
|
||||
passthru("rm -rf ".__DIR__."/compile/*");
|
||||
passthru("rm -f ".__DIR__."/templates/inheritance/smarty/*");
|
||||
passthru("rm -f ".__DIR__."/templates/inheritance/twig/*");
|
||||
|
||||
echo "\nSmarty3 vs Aspect (more details)\n\n";
|
||||
|
||||
echo "Coming soon\n";
|
50
benchmark/templates/echo.php
Normal file
50
benchmark/templates/echo.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
$data = json_decode(file_get_contents(__DIR__.'/echo/data.json'), true);
|
||||
|
||||
exec("rm -rf ".__DIR__."/../compile/*");
|
||||
|
||||
require(__DIR__.'/../../vendor/autoload.php');
|
||||
$smarty = new Smarty();
|
||||
$smarty->compile_check = false;
|
||||
|
||||
$smarty->setTemplateDir(__DIR__);
|
||||
$smarty->setCompileDir(__DIR__."/../compile/");
|
||||
|
||||
$start = microtime(true);
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch('echo/smarty.tpl');
|
||||
var_dump("Smarty3: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch('echo/smarty.tpl');
|
||||
var_dump("Smarty3 cached: ".(microtime(true)-$start));
|
||||
|
||||
Twig_Autoloader::register();
|
||||
$loader = new Twig_Loader_Filesystem(__DIR__);
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => __DIR__."/../compile/",
|
||||
'autoescape' => false,
|
||||
'auto_reload' => false,
|
||||
));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $twig->loadTemplate('echo/twig.tpl');
|
||||
$template->render($data);
|
||||
var_dump("Twig: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $twig->loadTemplate('echo/twig.tpl');
|
||||
$template->render($data);
|
||||
var_dump("Twig cached: ".(microtime(true)-$start));
|
||||
|
||||
$aspect = Aspect::factory(__DIR__, __DIR__."/../compile/", Aspect::CHECK_MTIME);
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $aspect->fetch('echo/smarty.tpl', $data);
|
||||
var_dump("Aspect: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $aspect->fetch('echo/smarty.tpl', $data);
|
||||
var_dump("Aspect cached: ".(microtime(true)-$start));
|
||||
|
1017
benchmark/templates/echo/data.json
Normal file
1017
benchmark/templates/echo/data.json
Normal file
File diff suppressed because it is too large
Load Diff
1001
benchmark/templates/echo/smarty.tpl
Normal file
1001
benchmark/templates/echo/smarty.tpl
Normal file
File diff suppressed because it is too large
Load Diff
1001
benchmark/templates/echo/twig.tpl
Normal file
1001
benchmark/templates/echo/twig.tpl
Normal file
File diff suppressed because it is too large
Load Diff
50
benchmark/templates/foreach.php
Normal file
50
benchmark/templates/foreach.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
$data = json_decode(file_get_contents(__DIR__.'/foreach/data.json'), true);
|
||||
|
||||
exec("rm -rf ".__DIR__."/../compile/*");
|
||||
|
||||
require(__DIR__.'/../../vendor/autoload.php');
|
||||
$smarty = new Smarty();
|
||||
$smarty->compile_check = false;
|
||||
|
||||
$smarty->setTemplateDir(__DIR__);
|
||||
$smarty->setCompileDir(__DIR__."/../compile/");
|
||||
|
||||
$start = microtime(true);
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch('foreach/smarty.tpl');
|
||||
var_dump("Smarty3: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch('foreach/smarty.tpl');
|
||||
var_dump("Smarty3 cached: ".(microtime(true)-$start));
|
||||
|
||||
Twig_Autoloader::register();
|
||||
$loader = new Twig_Loader_Filesystem(__DIR__);
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => __DIR__."/../compile/",
|
||||
'autoescape' => false,
|
||||
'auto_reload' => false,
|
||||
));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $twig->loadTemplate('foreach/twig.tpl');
|
||||
$template->render($data);
|
||||
var_dump("Twig: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $twig->loadTemplate('foreach/twig.tpl');
|
||||
$template->render($data);
|
||||
var_dump("Twig cached: ".(microtime(true)-$start));
|
||||
|
||||
$aspect = Aspect::factory(__DIR__, __DIR__."/../compile/", Aspect::CHECK_MTIME | Aspect::INCLUDE_SOURCES);
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $aspect->fetch('foreach/smarty.tpl', $data);
|
||||
var_dump("Aspect: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $aspect->fetch('foreach/smarty.tpl', $data);
|
||||
var_dump("Aspect cached: ".(microtime(true)-$start));
|
||||
|
1017
benchmark/templates/foreach/data.json
Normal file
1017
benchmark/templates/foreach/data.json
Normal file
File diff suppressed because it is too large
Load Diff
4
benchmark/templates/foreach/smarty.tpl
Normal file
4
benchmark/templates/foreach/smarty.tpl
Normal file
@ -0,0 +1,4 @@
|
||||
<h1>Вывод 10 полей из 1000 элементов в цикле<h1>
|
||||
{foreach $array as $item}
|
||||
{$item.id} {$item.title} {$item.var1} {$item.var2} {$item.var3} {$item.var4} {$item.var5} {$item.var6} {$item.var5} {$item.var6}
|
||||
{/foreach}
|
4
benchmark/templates/foreach/twig.tpl
Normal file
4
benchmark/templates/foreach/twig.tpl
Normal file
@ -0,0 +1,4 @@
|
||||
<h1>Вывод 10 полей из 1000 элементов в цикле<h1>
|
||||
{% for item in array %}
|
||||
{{ item.id }} {{ item.title }} {{ item.var1 }} {{ item.var2 }} {{ item.var3 }} {{ item.var4 }} {{ item.var5 }} {{ item.var6 }} {{ item.var5 }} {{ item.var6 }}
|
||||
{% endfor %}
|
61
benchmark/templates/inheritance.php
Normal file
61
benchmark/templates/inheritance.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
$data = array(
|
||||
"inh" => 'inheritance',
|
||||
"var1" => 'val1'
|
||||
);
|
||||
|
||||
function trace() {
|
||||
$e = new Exception();
|
||||
echo $e->getTraceAsString();
|
||||
ob_flush();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
exec("rm -rf ".__DIR__."/../compile/*");
|
||||
|
||||
require(__DIR__.'/../../vendor/autoload.php');
|
||||
|
||||
$smarty = new Smarty();
|
||||
$smarty->compile_check = false;
|
||||
|
||||
$smarty->setTemplateDir(__DIR__);
|
||||
$smarty->setCompileDir(__DIR__."/../compile/");
|
||||
|
||||
$start = microtime(true);
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch('inheritance/smarty/b100.tpl');
|
||||
var_dump("Smarty3: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch('inheritance/smarty/b100.tpl');
|
||||
var_dump("Smarty3 cached: ".(microtime(true)-$start));
|
||||
|
||||
Twig_Autoloader::register();
|
||||
$loader = new Twig_Loader_Filesystem(__DIR__);
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => __DIR__."/../compile/",
|
||||
'autoescape' => false,
|
||||
'auto_reload' => false,
|
||||
));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $twig->loadTemplate('inheritance/twig/b100.tpl');
|
||||
$template->render($data);
|
||||
var_dump("Twig: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $twig->loadTemplate('inheritance/twig/b100.tpl');
|
||||
$template->render($data);
|
||||
var_dump("Twig cached: ".(microtime(true)-$start));
|
||||
|
||||
$aspect = Aspect::factory(__DIR__, __DIR__."/../compile/", Aspect::CHECK_MTIME);
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $aspect->fetch('inheritance/smarty/b100.tpl', $data);
|
||||
var_dump("Aspect: ".(microtime(true)-$start));
|
||||
|
||||
$start = microtime(true);
|
||||
$template = $aspect->fetch('inheritance/smarty/b100.tpl', $data);
|
||||
var_dump("Aspect cached: ".(microtime(true)-$start));
|
||||
|
1017
benchmark/templates/inheritance/data.json
Normal file
1017
benchmark/templates/inheritance/data.json
Normal file
File diff suppressed because it is too large
Load Diff
10
benchmark/templates/inheritance/smarty.gen.php
Normal file
10
benchmark/templates/inheritance/smarty.gen.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$b0 = '<h1>Вывод статических данных в 500 наследуемых блоков</h1>' . "\r\n";
|
||||
for($i = 1; $i < 501; $i++)
|
||||
{
|
||||
$b0 .= '{block b'.$i.'}{/block}'."\r\n";
|
||||
$data = '{extends "inheritance/smarty/b'.($i-1).'.tpl"}' . "\r\n";
|
||||
$data .= '{block b'.$i.'}data'.$i.'{/block}' . "\r\n";
|
||||
file_put_contents(__DIR__.'/smarty/b'.$i.'.tpl', $data);
|
||||
}
|
||||
file_put_contents(__DIR__.'/smarty/b0.tpl', $b0);
|
10
benchmark/templates/inheritance/twig.gen.php
Normal file
10
benchmark/templates/inheritance/twig.gen.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$b0 = '<h1>Вывод статических данных в 500 наследуемых блоков</h1>' . "\r\n";
|
||||
for($i = 1; $i < 501; $i++)
|
||||
{
|
||||
$b0 .= '{% block b'.$i.' %}{% endblock %}'."\r\n";
|
||||
$data = '{% extends "inheritance/twig/b'.($i-1).'.tpl" %}' . "\r\n";
|
||||
$data .= '{% block b'.$i.' %}data'.$i.'{% endblock %}' . "\r\n";
|
||||
file_put_contents(__DIR__.'/twig/b'.$i.'.tpl', $data);
|
||||
}
|
||||
file_put_contents(__DIR__.'/twig/b0.tpl', $b0);
|
Reference in New Issue
Block a user