Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Первый вариант ##
- $mt1 = microtime(true);
- require '../libs/Smarty.class.php';
- $smarty = new Smarty;
- $smarty->template_dir = 'templates';
- $smarty->compile_dir = 'templates_c';
- $smarty->compile_check = true;
- $smarty->debugging = true;
- for ($i = 0; $i < 20; $i++) {
- //Создадим переменную для примера
- $name1 = 'V1';
- $name2 = 'V2';
- $name3 = 'V3';
- //Передаем переменную в шаблонизатор Smarty
- $smarty->assign('name1',$name1);
- $smarty->assign('name2',$name2);
- $smarty->assign('name3',$name3);
- //Выводим шаблон на экран
- $smarty->display('main.tpl');
- }
- $mt2 = microtime(true); $mt3 = $mt2-$mt1; echo "Время: $mt3";
- // 20 выводов - Время: 0.58260607719421
- // 20 выводов - Время: 0.55610704421997
- // 20 выводов - Время: 0.56068897247314
- ## Второй вариант (вынесем создание переменной и передачу из цикла) ##
- //Создадим переменную для примера
- $name1 = 'V1';
- $name2 = 'V2';
- $name3 = 'V3';
- //Передаем переменную в шаблонизатор Smarty
- $smarty->assign('name1',$name1);
- $smarty->assign('name2',$name2);
- $smarty->assign('name3',$name3);
- for ($i = 0; $i < 20; $i++) {
- //Выводим шаблон на экран
- $smarty->display('main.tpl');
- }
- // 20 выводов - Время полностью аналогично: 0.56 - 0.57
- ## Без шаблонизатора, т.е. так ##
- $mt1 = microtime(true);
- //Создадим переменную для примера
- $name1 = 'V1';
- $name2 = 'V2';
- $name3 = 'V3';
- for ($i = 0; $i < 20; $i++) {
- echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
- <html xmlns=\"http://www.w3.org/1999/xhtml\">
- <head>
- <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
- </head>
- <body>
- $name1
- $name2
- $name3
- </body>
- </html>";
- }
- $mt2 = microtime(true); $mt3 = $mt2-$mt1; echo "Время: $mt3";
- // 20 выводов - Время: 6.1988830566406E-5 Это где-то 0,00010 т.е. в 5600 раз медленнее ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement