Created
June 24, 2014 21:55
-
-
Save belichuk/dd3d15fbbfb4622008f0 to your computer and use it in GitHub Desktop.
patTemplate vs. Twig
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
<?php | |
function microtime_float() | |
{ | |
list($usec, $sec) = explode(' ', microtime()); | |
return ((float)$usec + (float)$sec); | |
} | |
require_once "../sqlconn.php"; | |
$params = array( | |
'doctype' => '<!DOCTYPE html>', | |
'title' => 'Demo application', | |
'script' => 'console.log("Demo application");', | |
'body' => '<h1>Demo application</h1>' | |
); | |
$i = 0; | |
$attempts = 1000; | |
$twig = new TwigLoad(dirname(__FILE__), false); | |
$oPage = new patTemplate_v2(); | |
$oPage->setBasedir("./"); | |
$oPage->readTemplatesFromFile("test.tmpl.html"); | |
$oPage->addVars('page', $params); | |
$time_start1 = microtime_float(); | |
for ($i=0;$i<$attempts;$i++) { | |
$twigContent = $twig->render('test.twig', $params); | |
} | |
$time_end1 = microtime_float(); | |
$time_start2 = microtime_float(); | |
for ($i=0;$i<$attempts;$i++) { | |
$patContent = $oPage->getParsedTemplate('page'); | |
} | |
$time_end2 = microtime_float(); | |
echo 'twig render time: ' . ($time_end1 - $time_start1) . '<br />'; | |
echo 'patT render time: ' . ($time_end2 - $time_start2) . '<br />'; |
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
<patTemplate:tmpl name="page"> | |
{DOCTYPE} | |
<html> | |
<head> | |
<title>{TITLE}</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
{SCRIPT} | |
</script> | |
{BODY} | |
</body> | |
</html> | |
</patTemplate:tmpl> |
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
{{ doctype | raw }} | |
<html> | |
<head> | |
<title>{{ title }}</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
{{ script | raw }} | |
</script> | |
{{ body | raw }} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment