mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Dev, dev and dev. Also, docs, docs and docs.
This commit is contained in:
68
benchmark/scripts/bootstrap.php
Normal file
68
benchmark/scripts/bootstrap.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
require(__DIR__.'/../../vendor/autoload.php');
|
||||
|
||||
class Benchmark {
|
||||
public static $t = "%8s: %-22s %10.4f sec, %10.1f MiB\n";
|
||||
|
||||
public static function smarty3($tpl, $data, $double, $message) {
|
||||
$smarty = new Smarty();
|
||||
$smarty->compile_check = false;
|
||||
|
||||
$smarty->setTemplateDir(__DIR__.'/../templates');
|
||||
$smarty->setCompileDir(__DIR__."/../compile/");
|
||||
|
||||
if($double) {
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch($tpl);
|
||||
}
|
||||
|
||||
$start = microtime(true);
|
||||
$smarty->assign($data);
|
||||
$smarty->fetch($tpl);
|
||||
|
||||
printf(self::$t, __FUNCTION__, $message, round(microtime(true)-$start, 4), round(memory_get_peak_usage()/1024/1024, 2));
|
||||
}
|
||||
|
||||
public static function twig($tpl, $data, $double, $message) {
|
||||
|
||||
Twig_Autoloader::register();
|
||||
$loader = new Twig_Loader_Filesystem(__DIR__.'/../templates');
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => __DIR__."/../compile/",
|
||||
'autoescape' => false,
|
||||
'auto_reload' => false,
|
||||
));
|
||||
|
||||
if($double) {
|
||||
$twig->loadTemplate($tpl)->render($data);
|
||||
}
|
||||
|
||||
$start = microtime(true);
|
||||
$twig->loadTemplate($tpl)->render($data);
|
||||
printf(self::$t, __FUNCTION__, $message, round(microtime(true)-$start, 4), round(memory_get_peak_usage()/1024/1024, 2));
|
||||
}
|
||||
|
||||
public static function aspect($tpl, $data, $double, $message) {
|
||||
|
||||
$aspect = Aspect::factory(__DIR__.'/../templates', __DIR__."/../compile/");
|
||||
|
||||
if($double) {
|
||||
$aspect->fetch($tpl, $data);
|
||||
}
|
||||
$start = microtime(true);
|
||||
$aspect->fetch($tpl, $data);
|
||||
printf(self::$t, __FUNCTION__, $message, round(microtime(true)-$start, 4), round(memory_get_peak_usage()/1024/1024, 2));
|
||||
}
|
||||
|
||||
public static function run($engine, $template, $data, $double, $message) {
|
||||
passthru(sprintf("php %s/run.php --engine '%s' --template '%s' --data '%s' --message '%s' %s", __DIR__, $engine, $template, $data, $message, $double ? '--double' : ''));
|
||||
}
|
||||
|
||||
public static function runs($engine, $template, $data) {
|
||||
self::run($engine, $template, $data, false, '!compiled and !loaded');
|
||||
self::run($engine, $template, $data, false, 'compiled and !loaded');
|
||||
self::run($engine, $template, $data, true, 'compiled and loaded');
|
||||
echo "\n";
|
||||
}
|
||||
}
|
15
benchmark/scripts/run.php
Normal file
15
benchmark/scripts/run.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
$opt = getopt("", array(
|
||||
"engine:",
|
||||
"template:",
|
||||
"data:",
|
||||
"double",
|
||||
"message:"
|
||||
));
|
||||
|
||||
require_once __DIR__.'/bootstrap.php';
|
||||
|
||||
extract($opt);
|
||||
|
||||
Benchmark::$engine($template, json_decode(file_get_contents($data), true), isset($double), $message);
|
Reference in New Issue
Block a user