Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Slow include_once / require_once

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
DeyV
Smarty Rookie


Joined: 01 Jul 2003
Posts: 6
Location: Poland

PostPosted: Tue Jan 11, 2005 11:49 am    Post subject: Slow include_once / require_once Reply with quote

If some blocks (ex. in method) of code runs more that one times, the include_once can be slow. Why?
Because on all the times work that slow, how include().

Real better method:
[php:1:cf64777e16]<?php
static $bIncCoreGetMicrotime;
if( empty( $bIncCoreGetMicrotime ) ) {
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
$bIncCoreGetMicrotime = true;
}
?>[/php:1:cf64777e16]


Last edited by DeyV on Tue Jan 11, 2005 7:53 pm; edited 1 time in total
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jan 11, 2005 4:51 pm    Post subject: Reply with quote

oh, please show us some numbers how much faster your approach is.
this is very interesting.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
DeyV
Smarty Rookie


Joined: 01 Jul 2003
Posts: 6
Location: Poland

PostPosted: Tue Jan 11, 2005 7:14 pm    Post subject: Reply with quote

example one:

[php:1:4b3becb60e]<?php
for( $i=0; $i <1000; $i ++ )
{
echo $i. ' ' ;
include_once '1.php';
echo '<br />';
}

?>[/php:1:4b3becb60e]
time: 0.249340057373 s


example two:
[php:1:4b3becb60e]<?php
for( $i=0; $i < 1000; $i ++ )
{
echo $i. ' ' ;
static $bInc;
if( empty( $bInc ) )
{
include_once '1.php';
$bInc = true;
}
echo '<br />';
}
?>[/php:1:4b3becb60e]
time: 0.0045371055603 s


file 1.php
[php:1:4b3becb60e]<?php
function test( ){
echo 'simple test';
}
?>[/php:1:4b3becb60e]


full code and trace from xdebug
http://mstudio.nq.pl/php_pl/index.php?udir=/speed
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP