473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Right output ...

Hi guys,

just wondering - which method of output is more fast and use less system
resources. The page being build with outup from multiple functions. So, is
it better to output each function result directly with "echo" construction:

echo "string1";
echo "string2";
................
echo "stringN";

or maybe better to collect all outputs in a variable first:

$out.= "string1";
$out.= "string2";
................
$out.= "stringN";
echo $out;

Maybe someone made a kind of research in this field :)
--
Web Design Essex | Multimedia | Printing http://nextwave.co.uk
May 30 '06 #1
1 1225
Berimor wrote:
Hi guys,

just wondering - which method of output is more fast and use less system
resources. The page being build with outup from multiple functions. So,
is it better to output each function result directly with "echo"
construction:

echo "string1";
echo "string2";
...............
echo "stringN";

or maybe better to collect all outputs in a variable first:

$out.= "string1";
$out.= "string2";
...............
$out.= "stringN";
echo $out;

Maybe someone made a kind of research in this field :)
--Web Design Essex | Multimedia | Printing http://nextwave.co.uk


Well, I have a few moments to play right now...

Some quick empirical tests:
[foo1.php]
<?php
for($i=0; $i < 1000000; $i++ ) {
echo "foo\n";
}
?>

[foo2.php]
<?php
for( $i=0; $i < 1000000; $i++) {
$foo .= "foo\n";
}
echo $foo;
?>

Running for 100,000 and 1,000,000 cycles produces:

100,000 1,000,000
foo R 0.213 1.317
U 0.196 1.292
S 0.016 0.024

foo1 R 1.156 10.590
U 0.704 5.708
S 0.452 4.876

foo2 R 0.540 5.887
U 0.388 3.760
S 0.152 2.128

Notes:
R - Wall clock, S - Time in the O/S, U - Time in the user program
All times are in seconds and were taken with the Gnu 'time' command.
The 'foo' process performs the loop but does not echo or concatenate. It
presents the base overhead of invoking php and doing the loop.
All output was sent to /dev/null to remove any display buffer lag.

As you can see, concatenation is much lighter weight than echoing.

I then changed foo1.php to include an ob_start() and ob_flush() set.

1,000,000
foo3 R 2.136
U 2.068
S 0.068

and for foo2.php

1,000,000
foo4 R 5.746
U 3.760
S 1.988

The moral seems to be that if you care about output speed, using the
output buffer with smaller data pieces appears to be your best bet.

-david-

May 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Paul Kooistra | last post by:
I need a tool to browse text files with a size of 10-20 Mb. These files have a fixed record length of 800 bytes (CR/LF), and containt records used to create printed pages by an external company. ...
2
by: Jason | last post by:
Hello, I have a class, transCore, that does certain work, and by default, prints its progress to the stand output. Later, I will to write a GUI class that encapsulate the transCore class. I...
22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
3
by: deanfamily11 | last post by:
Ok, here's another problem I'm having. I've tried several different things, but I just can't get anything to be right justified. Any thoughts? #include <iostream> #include <iomanip>...
5
by: Pioneer | last post by:
Hi, column nme: TEMP Datatype: CHAR length: 6 the value we are getting is TEMP 2X , SWD ,
2
by: johkar | last post by:
My right column content is created dynamically by an application so it will vary in height. When the main content of the page takes up more vertical space than the rigth column, I want the content...
4
by: Rich Shepard | last post by:
I have this print statement in a function: print '%2d $%11.2f $%10.2f $%9.2f $%9.2f' %(nper, pv, diff, ten, bonus) and I would like to have the output right justified in the specified...
1
by: anitawa | last post by:
Hi. I have a dilemma. Here is my xml. <time> <hour>1</hour> <minute>0</minute> </time> <time timezone="PST"> <hour>1</hour> <minute>15</hour>
52
by: marc | last post by:
Hello, Is it possible to right pad with "0" (or other character != blank) ? for example : 1 , length 10 ="1000000000" I've tried with sprintf but I can only left pad with "0" or right pad with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.