Hallo zusammen,
zur Zeit beschäftige ich mit der Trennung von Code u. Layout,
habe verschiedene Template-Engines ausprobiert u. auch deren
Performance getestet.
aufgefallen ist mir, das Smarty gegenüber einer PHP-Lösung
5 x langsamer ist
Beispiel:
Temlatelösung nur mit Php:
<?php
$navigation = "<ul>
<li>Seite 1</li>
<li>Seite 2</li>
<li>Seite 3</li>
<li>Seite 4</li>
</ul>
";
$title = "Templatetest mit Smarty u. PHP";
$content = "Lorem ipsum Lorem ipsum Lorem ipsum
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
";
include("php.tpl.htm");
?>
das Template (php.tpl.htm):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php print $title; ?></title>
</head>
<body>
<div id="navigation">
<?php print $navigation; ?>
</div>
<div id="content">
<h1><?php print $title; ?></h1>
<p><?php print $content; ?></p>
</div>
</body>
</html>
nun das gleiche mit Smarty:
<?php
require('Smarty.class.php');
$smarty = new Smarty;
// ... $smarty Konfiguration ...
$smarty->caching = TRUE;
$navigation = "<ul>
<li>Seite 1</li>
<li>Seite 2</li>
<li>Seite 3</li>
<li>Seite 4</li>
</ul>
";
$title = "Templatetest mit Smarty u. PHP";
$content = "Lorem ipsum Lorem ipsum Lorem ipsum
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
";
$smarty->assign('navigation', $navigation);
$smarty->assign('title', $title);
$smarty->assign('content', $content);
$smarty->display('smarty.tpl.htm');
?>
das Smartytemplate lasse ich mal weg s.o
( anstatt <?php print $navigation; ?> {$navigation} )
zugegeben ist das Beispiel sehr simpel, in einer echten
Anwendung kommen dann noch Datenbankabfragen u. mehr dazu.
Ich hab allerdings meine Zweifel ob man durch das Caching
von Smarty die Zeit aufholen kann.
was meint Ihr ?
Grüße Udo