View previous topic :: View next topic |
Author |
Message |
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 4:04 pm Post subject: Performance decrease |
|
|
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 |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sat Apr 26, 2003 4:19 pm Post subject: |
|
|
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 |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 4:30 pm Post subject: |
|
|
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 |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 4:33 pm Post subject: |
|
|
found a tool, will run some benchmarks |
|
Back to top |
|
aloner Smarty Rookie
Joined: 24 Apr 2003 Posts: 24
|
Posted: Sat Apr 26, 2003 4:35 pm Post subject: |
|
|
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 |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sat Apr 26, 2003 4:35 pm Post subject: |
|
|
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 |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 4:44 pm Post subject: |
|
|
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
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 |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 4:49 pm Post subject: |
|
|
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 |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sat Apr 26, 2003 6:12 pm Post subject: |
|
|
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 |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 6:15 pm Post subject: |
|
|
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 |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sat Apr 26, 2003 6:28 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Apr 26, 2003 6:35 pm Post subject: |
|
|
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 |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 6:43 pm Post subject: |
|
|
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 |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sat Apr 26, 2003 6:46 pm Post subject: |
|
|
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 |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 6:53 pm Post subject: |
|
|
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 |
|
|