473,413 Members | 2,056 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,413 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 1228
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.