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:
22
benchmark/aspect/benchmark/compile.aspect.php
Normal file
22
benchmark/aspect/benchmark/compile.aspect.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
use MF\Aspect;
|
||||
require_once __DIR__ . "/../../../lib/Autoload.php";
|
||||
|
||||
Aspect::addTemplateDir(__DIR__.'/../templates');
|
||||
Aspect::setCompileDir(__DIR__.'/../compiled');
|
||||
$total = 0;
|
||||
|
||||
$t = microtime(1);
|
||||
$tpl = Aspect::compile('syntax.tpl');
|
||||
$t = microtime(1) - $t;
|
||||
var_dump("First compile: ".$t);
|
||||
|
||||
|
||||
$t = microtime(1);
|
||||
$tpl = Aspect::compile('syntax.tpl');
|
||||
$t = microtime(1) - $t;
|
||||
var_dump("Second compile: ".$t);
|
||||
|
||||
|
||||
var_dump("Pick memory: ".memory_get_peak_usage());
|
||||
?>
|
||||
23
benchmark/aspect/benchmark/compile.smarty3.php
Normal file
23
benchmark/aspect/benchmark/compile.smarty3.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
require_once "/data/downloads/Smarty3/libs/Smarty.class.php";
|
||||
|
||||
$smarty = new Smarty();
|
||||
|
||||
$smarty->addTemplateDir(__DIR__.'/../templates');
|
||||
$smarty->setCompileDir(__DIR__.'/../compiled');
|
||||
|
||||
$t = microtime(1);
|
||||
$tpl = $smarty->createTemplate('syntax.tpl');
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl->compileTemplateSource();
|
||||
$t = microtime(1) - $t;
|
||||
var_dump("First compile: ".$t);
|
||||
|
||||
$t = microtime(1);
|
||||
$tpl = $smarty->createTemplate('syntax.tpl');
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl->compileTemplateSource();
|
||||
$t = microtime(1) - $t;
|
||||
var_dump("Second compile: ".$t);
|
||||
|
||||
var_dump("Pick memory: ".memory_get_peak_usage());
|
||||
87
benchmark/aspect/benchmark/data.php
Normal file
87
benchmark/aspect/benchmark/data.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
class obj {
|
||||
public $value = "obj.value property";
|
||||
public $num = 777;
|
||||
|
||||
public function method() {
|
||||
return "object method";
|
||||
}
|
||||
|
||||
public function methodArgs($i, $j, $k, $str, $value) {
|
||||
return "object method with ars $i, $j, $k, $str, $value";
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return "object";
|
||||
}
|
||||
|
||||
public function getSelf() {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
"title" => "syntax test page",
|
||||
|
||||
"user" => array(
|
||||
"email" => 'bzick@megagroup.ru',
|
||||
"name" => 'Ivan'
|
||||
),
|
||||
|
||||
"data" => array(
|
||||
1 => array(
|
||||
"foo" => "data.1.foo value"
|
||||
),
|
||||
2 => 4,
|
||||
4 => "data.four value",
|
||||
5 => array(
|
||||
"bar" => "data.5.baz value",
|
||||
"baz" => array(
|
||||
"foo" => "data.5.baz.foo value"
|
||||
)
|
||||
),
|
||||
6 => array(
|
||||
"foo" => "data.6.foo value"
|
||||
),
|
||||
"bar" => "data.bar value",
|
||||
"barz" => "data.barz value",
|
||||
"baz_key" => "baz",
|
||||
"foo" => array(
|
||||
"bar" => "data.foo.baz value",
|
||||
"baz" => array(
|
||||
"foo" => "data.foo.baz.foo value",
|
||||
"ls" => array(
|
||||
4 => "data.foo.baz.ls.4 value",
|
||||
5 => 555
|
||||
)
|
||||
)
|
||||
),
|
||||
"obj" => new obj(),
|
||||
"tpl_name" => 'subdir/subtpl'
|
||||
),
|
||||
|
||||
"foo_key" => "foo",
|
||||
"bar_key" => "bar",
|
||||
"barz_key" => "barz",
|
||||
"baz_key" => "baz",
|
||||
|
||||
"item" => "some item",
|
||||
"x" => 1,
|
||||
"y" => 2,
|
||||
"tpl_name" => "subtpl",
|
||||
|
||||
"contacts" => array(
|
||||
array(
|
||||
"foo" => "bar",
|
||||
"foo1" => "bar1",
|
||||
"foo2" => "bar2",
|
||||
),
|
||||
array(
|
||||
"baz" => "buh",
|
||||
"baz1" => "buh1",
|
||||
"baz2" => "buh2",
|
||||
)
|
||||
),
|
||||
"logged_in" => false
|
||||
);
|
||||
25
benchmark/aspect/benchmark/execute.aspect.php
Normal file
25
benchmark/aspect/benchmark/execute.aspect.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
use MF\Aspect;
|
||||
require_once __DIR__ . "/../../../lib/Autoload.php";
|
||||
|
||||
Aspect::addTemplateDir(__DIR__.'/../templates');
|
||||
Aspect::setCompileDir(__DIR__.'/../compiled');
|
||||
|
||||
/*$ct = microtime(1);
|
||||
$data = Aspect::compile('syntax.tpl',0);
|
||||
$ct = microtime(1) - $ct;
|
||||
echo "\n=====================\nCompile: $ct\n";*/
|
||||
|
||||
$_data = require_once __DIR__.'/data.php';
|
||||
|
||||
$data = Aspect::fetch('syntax.tpl', $_data, 0);
|
||||
|
||||
|
||||
$dt = microtime(1);
|
||||
$data = Aspect::fetch('syntax.tpl', $_data, 0);
|
||||
$dt = microtime(1) - $dt;
|
||||
|
||||
$data = MF\Misc\Str::strip($data, true);
|
||||
echo "$data\n====\n".md5($data)."\n=====================\nDisplay: $dt\n";
|
||||
var_dump("Pick memory: ".memory_get_peak_usage());
|
||||
?>
|
||||
23
benchmark/aspect/benchmark/execute.native.php
Normal file
23
benchmark/aspect/benchmark/execute.native.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
use MF\Aspect;
|
||||
require_once __DIR__ . "/../../../lib/Autoload.php";
|
||||
|
||||
|
||||
$tpl = require_once __DIR__.'/data.php';
|
||||
require __DIR__.'/../templates/syntax.php';
|
||||
require __DIR__.'/../templates/subdir/subtpl.php';
|
||||
|
||||
ob_start();
|
||||
template_syntax($tpl);
|
||||
$data = ob_get_clean();
|
||||
|
||||
$dt = microtime(1);
|
||||
ob_start();
|
||||
template_syntax($tpl);
|
||||
$data = ob_get_clean();
|
||||
$dt = microtime(1) - $dt;
|
||||
|
||||
$data = MF\Misc\Str::strip($data, true);
|
||||
echo "$data\n====\n".md5($data)."\n=====================\nDisplay: $dt\n";
|
||||
var_dump("Pick memory: ".memory_get_peak_usage());
|
||||
?>
|
||||
25
benchmark/aspect/benchmark/execute.simple.aspect.php
Normal file
25
benchmark/aspect/benchmark/execute.simple.aspect.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
use MF\Aspect;
|
||||
require_once __DIR__ . "/../../../lib/Autoload.php";
|
||||
|
||||
Aspect::setTemplateDir(__DIR__.'/../templates');
|
||||
Aspect::setCompileDir(__DIR__.'/../compiled');
|
||||
|
||||
$ct = microtime(1);
|
||||
$data = Aspect::compile('simple.tpl',0);
|
||||
$ct = microtime(1) - $ct;
|
||||
|
||||
$_data = array(
|
||||
"name" => "Ivan",
|
||||
"email" => "bzick@megagroup.ru"
|
||||
);
|
||||
|
||||
$data = Aspect::fetch('simple.tpl', $_data, 0);
|
||||
|
||||
$dt = microtime(1);
|
||||
$data = Aspect::fetch('simple.tpl', $_data, 0);
|
||||
$dt = microtime(1) - $dt;
|
||||
|
||||
|
||||
echo "\n=====================\nCompile: $ct\nDisplay: $dt\n";
|
||||
?>
|
||||
29
benchmark/aspect/benchmark/execute.simple.smarty3.php
Normal file
29
benchmark/aspect/benchmark/execute.simple.smarty3.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once "/data/downloads/Smarty3/libs/Smarty.class.php";
|
||||
|
||||
$smarty = new Smarty();
|
||||
|
||||
$smarty->addTemplateDir(__DIR__.'/../templates');
|
||||
$smarty->setCompileDir(__DIR__.'/../compiled');
|
||||
|
||||
$ct = microtime(1);
|
||||
$tpl = $smarty->createTemplate('simple.tpl');
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl->compileTemplateSource();
|
||||
$ct = microtime(1) - $ct;
|
||||
|
||||
$_data = array(
|
||||
"name" => "Ivan",
|
||||
"email" => "bzick@megagroup.ru"
|
||||
);
|
||||
|
||||
$smarty->assign($_data);
|
||||
$data = $smarty->fetch('simple.tpl');
|
||||
|
||||
$t = microtime(1);
|
||||
$smarty->assign($_data);
|
||||
$data = $smarty->fetch('simple.tpl');
|
||||
$dt = microtime(1) - $t;
|
||||
|
||||
|
||||
echo "\n=====================\nCompile: $ct\nDisplay: $dt\n";
|
||||
29
benchmark/aspect/benchmark/execute.smarty3.php
Normal file
29
benchmark/aspect/benchmark/execute.smarty3.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once "/data/downloads/Smarty3/libs/Smarty.class.php";
|
||||
require_once __DIR__ . "/../../../lib/Autoload.php";
|
||||
$smarty = new Smarty();
|
||||
|
||||
$smarty->addTemplateDir(__DIR__.'/../templates');
|
||||
$smarty->setCompileDir(__DIR__.'/../compiled');
|
||||
|
||||
/*$ct = microtime(1);
|
||||
$tpl = $smarty->createTemplate('syntax.tpl');
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
/*$tpl->compileTemplateSource();
|
||||
$ct = microtime(1) - $ct;
|
||||
echo "\n=====================\nCompile: $ct\n";
|
||||
*/
|
||||
|
||||
$_data = require_once __DIR__.'/data.php';
|
||||
|
||||
$smarty->assign($_data);
|
||||
$data = $smarty->fetch('syntax.tpl');
|
||||
|
||||
$t = microtime(1);
|
||||
$smarty->assign($_data);
|
||||
$data = $smarty->fetch('syntax.tpl');
|
||||
$dt = microtime(1) - $t;
|
||||
|
||||
$data = MF\Misc\Str::strip($data, true);
|
||||
echo "$data\n====\n".md5($data)."\n=====================\nDisplay: $dt\n";
|
||||
var_dump("Pick memory: ".memory_get_peak_usage());
|
||||
47
benchmark/aspect/benchmark/foreach.last.php
Normal file
47
benchmark/aspect/benchmark/foreach.last.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
$a = new ArrayIterator(str_split(str_pad("", 4, "a")));
|
||||
|
||||
$_t = null;
|
||||
$t = microtime(1);
|
||||
reset($a);
|
||||
while($v = current($a)) {
|
||||
$k = key($a);
|
||||
next($a);
|
||||
if(key($a) === null) {
|
||||
var_dump("last");
|
||||
}
|
||||
//var_dump($v);
|
||||
}
|
||||
print_r("\n\nWhile: ".(microtime(1) - $t)."\n\n");
|
||||
|
||||
$t = microtime(1);
|
||||
$c = count($a);
|
||||
foreach($a as $k => $v) {
|
||||
if(!--$c) var_dump("last");
|
||||
//var_dump($v);
|
||||
}
|
||||
|
||||
print_r("\n\nforeach + count: ".(microtime(1) - $t)."\n\n");
|
||||
|
||||
$t = microtime(1);
|
||||
reset($a);
|
||||
while(list($k, $v) = each($a)) {
|
||||
if(key($a) === null) {
|
||||
var_dump("last");
|
||||
}
|
||||
/*next($a);
|
||||
if(key($a) === null) {
|
||||
var_dump("last");
|
||||
}*/
|
||||
//var_dump($v);
|
||||
}
|
||||
print_r("\neach: ".(microtime(1) - $t)."\n\n");
|
||||
|
||||
$t = microtime(1);
|
||||
foreach($a as $k => $v) {
|
||||
//var_dump($v);
|
||||
}
|
||||
|
||||
print_r("\n\nforeach: ".(microtime(1) - $t)."\n\n");
|
||||
?>
|
||||
Reference in New Issue
Block a user