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

Performance decrease
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 4:04 pm    Post subject: Performance decrease Reply with quote

I am a little worried about performance, after applying the latest patch I seem to have an increase in loadtime (no cache, debug off, compiled templates), which is not what I am looking for...

Perhaps it's all those preg_replace, from what I've heard regular expressions are not good for performance

Perhaps someone would be interested in running a benchmark? comparing lastest CVS with pre2.5.0? Or tell me how to do a benchmark Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Sat Apr 26, 2003 4:19 pm    Post subject: Reply with quote

Benchmarking is easy

Code:
<?php
$start_time = microtime();

... put your code to bench in here ...

$end_time   = microtime();
$stime      = explode(" ", $start_time);
$start      = $stime[0] + $stime[1];
$etime      = explode(" ", $end_time);
$end        = $etime[0] + $etime[1];
print("Code took " . number_format($end - $start, 6) . " seconds to run");
?>


just make two files like that with the different code and run them and see the difference in time
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 4:30 pm    Post subject: Reply with quote

I was sort of thinking of like loading a page 200 times and taking the avarage, but I guess one would just do that with a loop...
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 4:33 pm    Post subject: Reply with quote

found a tool, will run some benchmarks
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
aloner
Smarty Rookie


Joined: 24 Apr 2003
Posts: 24

PostPosted: Sat Apr 26, 2003 4:35 pm    Post subject: Reply with quote

If you are about removal of redundant PHP markers - this is nothing to deal with perfomance - preg_replace() called only once at compile time.
_________________
Your ad here.
Back to top
View user's profile Send private message
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Sat Apr 26, 2003 4:35 pm    Post subject: Reply with quote

Then you can use the ab (ApacheBench) command from apache

Code:
ab -n 200 -c 10 http://site.com/script.php

_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 4:44 pm    Post subject: Reply with quote

index.php
Code:
<?php
   require_once('../lib/smarty/libs/Smarty.class.php');
   $smarty = new Smarty;
   $smarty->compile_id = 'test';
   $smarty->template_dir = dirname(__FILE__);
   $smarty->compile_dir = dirname(__FILE__) .'/../lib/smarty/templates_c/';

   $smarty->display('test.tpl');

?>

test.tpl
Code:
Hello world


Command: siege --url="http://build.tsn.dk/test/index.php"

Result:
Quote:
Lifting the server siege... done. Transactions: 159 hits
Availability: 100.00 %
Elapsed time: 17.21 secs
Data transferred: 3657 bytes
Response time: 0.71 secs
Transaction rate: 9.24 trans/sec
Throughput: 212.49 bytes/sec
Concurrency: 6.57
Successful transactions: 159
Failed transactions: 0

Smarty version: 2.5.0CVS


Response time: 0.71 secs
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 4:49 pm    Post subject: Reply with quote

index.php
Code:
<?php
   require_once('../lib/smarty/libs/Smarty.class.php');
   $smarty = new Smarty;
   $smarty->compile_id = 'test';
   $smarty->template_dir = dirname(__FILE__);
   $smarty->compile_dir = dirname(__FILE__) .'/../lib/smarty/templates_c/';

   $smarty->assign('name', 'John Doe');
   $smarty->display('test.tpl');

?>

test.tpl
Code:
Hello {$name}, wlcome to the world


Command: siege --url="http://build.tsn.dk/test/index.php"

Result:
Quote:
Lifting the server siege... done. Transactions: 161 hits
Availability: 100.00 %
Elapsed time: 24.99 secs
Data transferred: 7567 bytes
Response time: 1.43 secs
Transaction rate: 6.44 trans/sec
Throughput: 302.80 bytes/sec
Concurrency: 9.24
Successful transactions: 161
Failed transactions: 0

Smarty version: 2.5.0CVS


Response time: 1.43 secs
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Sat Apr 26, 2003 6:12 pm    Post subject: Reply with quote

ok you posted that both were 2.5.0CVS which is which
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 6:15 pm    Post subject: Reply with quote

Well they are both Smarty 2.5.0 CVS, the diffirence is the variable

I'll post some more benchmarks soon, busy with an assignment Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Sat Apr 26, 2003 6:28 pm    Post subject: Reply with quote

Well thats to be expected
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


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

PostPosted: Sat Apr 26, 2003 6:35 pm    Post subject: Reply with quote

i cannot reproduce your numbers.

if you use a tool like siege to benchmark smarty, you benchmark a lot more: your webserver setup, you network setup etc.

i don't know where your reponse-time 1.43 vs. 0.71 results from.

if i run a similar test i get for both, your first and your second script, 0.06 secs response time. when i run the test with Smarty-2.4.2 instead of CVS-Head i get the same 0.06.

when i benchmark smarty's-compiled template's performance i do often sth. more like:

Code:

<?php

set_time_limit(0);
$it = 100;

$smarty->clear_compiled_tpl();
$t0 = $smarty->_get_microtime();
for ($i=0; $i<$it; $i++) $smarty->fetch('bench/index.tpl');
$t1 = $smarty->_get_microtime();

printf("%s: %d iterations %f milliseconds\n", SMARTY_DIR, $it, ($t1-$t0)*1000.0);

?>


the clear-compiled-tpl gives equal conditions for each run, the template
hast to be compiled once.

this does not benchmark the load-time of smarty itself of course it almost measures the runtime of compiled smarty-templates.

i use other setups to measure other aspects of smarty's performance, the same above with force_compile=true to measure compile-performance for example.


of course tools like siege or ab are good to measure real-life-performance of a webpage. but you cannot profile the performance of an "echo $this->_tpl_var['foo'];" with that method. no way.

just my 2c
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 6:43 pm    Post subject: Reply with quote

Then please do a benchmark for us, you said you got 0.6 for both 2.4.2 and 2.5.0? how can that be? sounds very strange...

Try with a more complex template file...
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Sat Apr 26, 2003 6:46 pm    Post subject: Reply with quote

Personally I didnt see any change in speed between 2.4.2 and 2.5.0 but then again I am not really looking for it
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Sat Apr 26, 2003 6:53 pm    Post subject: Reply with quote

I'm going to have to optimize every part of my PHP code, since I just read some PHP benchmarks that shows what to do and not to do

like is_array() is 3x slower than isset()

and

$size = sizeof($s);
for($i=0; $i < $size; $i++)

is 1000% faster than
for($i=0; $i < sizeof($a); $i++)
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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