Re: [PHP] Print or Echo takes lots of time

2006-09-28 Thread Ivo F.A.C. Fokkema
On Tue, 26 Sep 2006 21:45:58 +1000, David Tulloh wrote:

 Google Kreme wrote:
 On 25 Sep 2006, at 06:11 , Sancar Saran wrote:
 ...
 
 If this is generating hundred of K of HTML, use ' instead of 
 
 (yes, it's faster).
 
 
 I've seen this stated several times and at first glance it seems to make
 sense.  The double quoted version has all the \n and related characters
 that need to be handled.
 
 Except that php is a C program and uses the printf family of functions.
  This means that all the single quoted strings actually have to be
 converted to escaped versions of double quoted strings, so internally
 '\n' becomes \\n.
 
 You can see this in some benchmarks, I ran the following script and a
 single quoted version from the command line.  I ran each 10 times,
 interleaved to try to balance changes in the system load.
 
 ?php
 $str=;
 for($i=0; $i1000; $i++)
 $str.=foo;
 ?
 
 I found that the double quoted version averaged 5.5516 seconds against
 the single quoted script of 5.5627.  Which really goes to show that
 while the double quoted version is faster the difference is almost
 completely irrelevent.

While we're at it (running benchmarks three times, varying amount of loops):

Benchmarking with 100K loops
Case 1 : 'Adding a 10-character single quoted string to a var'
Time   : 0.23s - 0.24s 
Case 2 : 'Adding a 10-character double quoted string to a var'
Time   : 0.23s - 0.24s 
Performance : Anywhere between Decreased 1.1% and Increased 26.7%

This seems really funny to me, cause I was under the impression a single
quoted string was faster... I remember benchmarking that before.



Benchmarking with 10K loops
Case 1 : 'Adding a 100-character single quoted string to a var'
Time   : 0.03s - 0.08s
Case 2 : 'Adding a 100-character double quoted string to a var'
Time   : 0.03s 
Performance : Anywhere between Increased 0.7% and Increased 66.9%

Still funny... and numbers get higher, too.



Benchmarking with 1M loops
Case 1 : 'Setting a var with a 100-character single quoted string'
Time   : 2.29s - 2.63s 
Case 2 : 'Setting a var with a 100-character double quoted string'
Time   : 2.53 - 2.78s 
Performance : Anywhere between Decreased 3.1% and Decreased 16.3%

Now this is probably what I saw previously and what made me decide using
single quotes where possible.



Benchmarking with 1M loops
Case 1 : 'Setting a var with a 100-character single quoted string incl. a 
variable (concat)'
Time   : 3.59s - 4.07s
Case 2 : 'Setting a var with a 100-character double quoted string incl. a 
variable'
Time   : 4.14s - 4.40s
Performance : Anywhere between Decreased 8.2% - Decreased 19.2%

Well, try not to use variables in a string, but concatenate it together.



Benchmarking with 1M loops
Case 1 : 'Setting a var with a 100-character double quoted string incl. a 
variable (concat)'
Time   : 3.58s - 3.79s
Case 2 : 'Setting a var with a 100-character double quoted string incl. a 
variable'
Time   : 4.12s - 5.24s
Performance : Anywhere between Decreased 14.9% - Decreased 38.4%

Same with using double quoted strings only...



Hey! It's coffee break already!

Ivo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-27 Thread Richard Lynch
On Wed, September 27, 2006 3:37 am, Sancar Saran wrote:
 Thanks for supporting, because of approaching the problem I don't want
 to
 change generate once echo one style.

 And I found solution like this,
 I split  variable into an array and generate loop for printing, mostly
 fix the
 problem.

 And more interesting, some times problem repeates himself. I believe
 this was
 connected to php memory performance.

 Anyhow is there any information about optimal echo or print size ?

You could try to generate some stats to add to the pool of knowledge.

I suspect it's so tied to hardware, load, OS, bandwidth-pipesize that
all that has to be reported to be useful.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread David Tulloh
Google Kreme wrote:
 On 25 Sep 2006, at 06:11 , Sancar Saran wrote:
 ...
 
 If this is generating hundred of K of HTML, use ' instead of 
 
 (yes, it's faster).
 

I've seen this stated several times and at first glance it seems to make
sense.  The double quoted version has all the \n and related characters
that need to be handled.

Except that php is a C program and uses the printf family of functions.
 This means that all the single quoted strings actually have to be
converted to escaped versions of double quoted strings, so internally
'\n' becomes \\n.

You can see this in some benchmarks, I ran the following script and a
single quoted version from the command line.  I ran each 10 times,
interleaved to try to balance changes in the system load.

?php
$str=;
for($i=0; $i1000; $i++)
$str.=foo;
?

I found that the double quoted version averaged 5.5516 seconds against
the single quoted script of 5.5627.  Which really goes to show that
while the double quoted version is faster the difference is almost
completely irrelevent.


David

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread Børge Holen
On Tuesday 26 September 2006 02:07, Robert Cummings wrote:
 On Mon, 2006-09-25 at 17:39 -0600, Google Kreme wrote:
  I'm sitting here with 4 Gigs of RAM trying to figure out how to use
  it all... :-)  (Me, in 2005)

 Not really related to the post... but I find a good way to eat up 4 gigs
 of RAM is to run several VMWare nodes :) Depending on what these nodes
 do, it can also be a great way to eat up those dual core processors :)

Forget 'bout em vmware stuff. Imagine putting those ramdisks to good use.



 Cheers,
 Rob.
 --
 ..

 | InterJinn Application Framework - http://www.interjinn.com |
 |
 ::
 :
 | An application and templating framework for PHP. Boasting  |
 | a powerful, scalable system for accessing system services  |
 | such as forms, properties, sessions, and caches. InterJinn |
 | also provides an extremely flexible architecture for   |
 | creating re-usable components quickly and easily.  |

 `'

-- 
---
Børge
Kennel Arivene 
http://www.arivene.net
---

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread Richard Lynch
On Mon, September 25, 2006 7:11 am, Sancar Saran wrote:
 When I was check the performance of my system I found interesting
 resuts.

 My code stores html output into a variable. When page creation
 complete I
 printed out the variable.

 Problem was generation html code takes 0.5 second and just
 echo $strPage takes 2.0 or more second.

 my code structure was.

 $strPage = html yada dayda;
 ...
 $strPage.=  another html tags;
 ...
 $strPage.= getSqlDataAndCreateSomeHtmlCOde();
 ...
 end of page creation.
 Current Total execution time 0.5 seconds.
 print $strPage;
 Current Total execution time 2.5 seconds.

 $strPage carries entire html structure (for example equal of 100K html
 code);

 excluding the cookie and other kind of header transfers and error
 messages,
 there was no print or echo command was submitted.

 Is there any idea about this latency and any idea to find problem...

You could try echo-ing it out in chunks instead of waiting until the
very end.

echo/print has to send the data out through the very narrow pipe to
Apache - the browser

If you send every little snippet one tiny piece at a time, you waste
resources.

If you wait until the end and send out some huge monster string, you
waste resources.

Find the balance if you can.

Depends on your hardware/bandwidth exactly where optimum is.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread Richard Lynch
On Tue, September 26, 2006 12:16 pm, Børge Holen wrote:
 On Tuesday 26 September 2006 02:07, Robert Cummings wrote:
 On Mon, 2006-09-25 at 17:39 -0600, Google Kreme wrote:
  I'm sitting here with 4 Gigs of RAM trying to figure out how to
 use
  it all... :-)  (Me, in 2005)

 Not really related to the post... but I find a good way to eat up 4
 gigs
 of RAM is to run several VMWare nodes :) Depending on what these
 nodes
 do, it can also be a great way to eat up those dual core processors
 :)

 Forget 'bout em vmware stuff. Imagine putting those ramdisks to good
 use.

I wonder what would happen if you put your swap on a RAM disk?

Wouldn't that be really fast?!

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread Curt Zirzow

On 9/26/06, Richard Lynch [EMAIL PROTECTED] wrote:

On Tue, September 26, 2006 12:16 pm, Børge Holen wrote:
 On Tuesday 26 September 2006 02:07, Robert Cummings wrote:
 On Mon, 2006-09-25 at 17:39 -0600, Google Kreme wrote:
  I'm sitting here with 4 Gigs of RAM trying to figure out how to
 use
  it all... :-)  (Me, in 2005)

 Not really related to the post... but I find a good way to eat up 4
 gigs
 of RAM is to run several VMWare nodes :) Depending on what these
 nodes
 do, it can also be a great way to eat up those dual core processors
 :)

 Forget 'bout em vmware stuff. Imagine putting those ramdisks to good
 use.

I wonder what would happen if you put your swap on a RAM disk?


I actually have done this, it works like a charm :)

you just have to ensure swap doesn't run out... of course i'd only
recomend this on a dedicated machine for like firewalling or a
gateway.

Curt

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread Richard Lynch
On Tue, September 26, 2006 6:35 pm, Curt Zirzow wrote:
 I wonder what would happen if you put your swap on a RAM disk?

 I actually have done this, it works like a charm :)

 you just have to ensure swap doesn't run out... of course i'd only
 recomend this on a dedicated machine for like firewalling or a
 gateway.

Like...

Wouldn't it just make more sense to not have swap at all?...

I mean, you can only be increasing overhead and whatnot...

I suppose if you just plain CANNOT build the system with no swap,
because the tools won't let you do that...

H.  Never tried to build a swap-less box, for obvious reasons...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread Robert Cummings
On Tue, 2006-09-26 at 18:46 -0500, Richard Lynch wrote:
 On Tue, September 26, 2006 6:35 pm, Curt Zirzow wrote:
  I wonder what would happen if you put your swap on a RAM disk?
 
  I actually have done this, it works like a charm :)
 
  you just have to ensure swap doesn't run out... of course i'd only
  recomend this on a dedicated machine for like firewalling or a
  gateway.
 
 Like...
 
 Wouldn't it just make more sense to not have swap at all?...
 
 I mean, you can only be increasing overhead and whatnot...
 
 I suppose if you just plain CANNOT build the system with no swap,
 because the tools won't let you do that...
 
 H.  Never tried to build a swap-less box, for obvious reasons...

*lol* I was gonna say, why the hell would anyone make swap into a
ramdisk when the memory used for the ramdisk would be better used as
primary RAM. I presumed you were joking Richard which you clarify above,
but Curtis now has me wondering :B The only time I'd use a ramdisk for
swap is if I had the extra cash to shell out for one of the pretend hard
drives that really map to RAM... like this sucker:

http://www.shoprbc.com/ca/shop/product_details.php?pid=13968

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Fwd: Re: [PHP] Print or Echo takes lots of time

2006-09-26 Thread Børge Holen


--  Forwarded Message  --

Subject: Re: [PHP] Print or Echo takes lots of time
Date: Wednesday 27 September 2006 06:37
From: Børge Holen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]

On Wednesday 27 September 2006 01:46, Richard Lynch wrote:
 On Tue, September 26, 2006 6:35 pm, Curt Zirzow wrote:
  I wonder what would happen if you put your swap on a RAM disk?
 
  I actually have done this, it works like a charm :)
 
  you just have to ensure swap doesn't run out... of course i'd only
  recomend this on a dedicated machine for like firewalling or a
  gateway.

 Like...

 Wouldn't it just make more sense to not have swap at all?...

 I mean, you can only be increasing overhead and whatnot...

 I suppose if you just plain CANNOT build the system with no swap,
 because the tools won't let you do that...

 H.  Never tried to build a swap-less box, for obvious reasons...

I've done that since '01.
Never any occurences (witch WILL happen whenever you run out). Of course
 never on a production machine, but my desktop and laptop sure got none.

 --
 Like Music?
 http://l-i-e.com/artists.htm

--
---
Børge
Kennel Arivene
http://www.arivene.net
---

---

-- 
---
Børge
Kennel Arivene 
http://www.arivene.net
---

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Print or Echo takes lots of time

2006-09-25 Thread Sancar Saran
Hi,

When I was check the performance of my system I found interesting resuts.

My code stores html output into a variable. When page creation complete I 
printed out the variable.

Problem was generation html code takes 0.5 second and just 
echo $strPage takes 2.0 or more second.

my code structure was.

$strPage = html yada dayda;
...
$strPage.=  another html tags;
...
$strPage.= getSqlDataAndCreateSomeHtmlCOde();
...
end of page creation. 
Current Total execution time 0.5 seconds.
print $strPage;
Current Total execution time 2.5 seconds.

$strPage carries entire html structure (for example equal of 100K html code);

excluding the cookie and other kind of header transfers and error messages, 
there was no print or echo command was submitted.

Is there any idea about this latency and any idea to find problem...

Regards

Sancar Saran

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-25 Thread Google Kreme

On 25 Sep 2006, at 06:11 , Sancar Saran wrote:

$strPage = html yada dayda;
...
$strPage.=  another html tags;
...
$strPage.= getSqlDataAndCreateSomeHtmlCOde();


If this is generating hundred of K of HTML, use ' instead of 

(yes, it's faster).

--  
I'm sitting here with 4 Megs of RAM trying to figure out how to use  
it all... :-)  (Me, in 1990)
I'm sitting here with 4 Gigs of RAM trying to figure out how to use  
it all... :-)  (Me, in 2005)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Print or Echo takes lots of time

2006-09-25 Thread Robert Cummings
On Mon, 2006-09-25 at 17:39 -0600, Google Kreme wrote:

 I'm sitting here with 4 Gigs of RAM trying to figure out how to use  
 it all... :-)  (Me, in 2005)

Not really related to the post... but I find a good way to eat up 4 gigs
of RAM is to run several VMWare nodes :) Depending on what these nodes
do, it can also be a great way to eat up those dual core processors :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php