473,472 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What performs better, theoreticaly?

What performs better, theoreticaly?
This
<?
echo date("d",time());
echo date("m",time());
echo date("Y",time());
?>
Or that?
<?
$time = time();
echo date("d",$time);
echo date("m",$time);
echo date("Y",$time);
?>
when does it get relevant?
thanks
Rolf
Apr 23 '07 #1
7 1665
On Apr 23, 10:39 am, "Rolf Mander" <rolf.man...@spam.comwrote:
What performs better, theoreticaly?
This
<?
echo date("d",time());
echo date("m",time());
echo date("Y",time());
?>
Or that?
<?
$time = time();
echo date("d",$time);
echo date("m",$time);
echo date("Y",$time);
?>
when does it get relevant?
thanks
Rolf
Theoretically the second one, since you only need to make 4 function
calls instead of six. It won't be relevant anytime soon.

Apr 23 '07 #2
On Mon, 23 Apr 2007 16:39:00 +0200, "Rolf Mander"
<ro*********@spam.comwrote:
>What performs better, theoreticaly?
This
<?
echo date("d",time());
echo date("m",time());
echo date("Y",time());
?>
there's a bug just waiting to happen, ok, only once per month at
midnight on the last day of the month.
--
Regards, Paul Herber, Sandrila Ltd.
Electronics for Visio http://www.electronics.sandrila.co.uk/
Apr 23 '07 #3
On Apr 23, 11:06 am, Paul Herber
<SubstituteMyFirstNameH...@pherber.comwrote:
On Mon, 23 Apr 2007 16:39:00 +0200, "Rolf Mander"

<rolf.man...@spam.comwrote:
What performs better, theoreticaly?
This
<?
echo date("d",time());
echo date("m",time());
echo date("Y",time());
?>

there's a bug just waiting to happen, ok, only once per month at
midnight on the last day of the month.

--
Regards, Paul Herber, Sandrila Ltd.
Electronics for Visio http://www.electronics.sandrila.co.uk/
And assuming you run the script at exactly the right millisecond.

Apr 23 '07 #4
Rolf Mander wrote:
<?
echo date("d",time());
echo date("m",time());
echo date("Y",time());
?>
Consider running this code at the stroke of midnight on Monday/Tuesday
next week.

<?
/* Today is Monday 30 April 2007 */
echo date("d",time());
/* It's midnight now. Clocks go 23:59:59 =00:00:00. */
/* Today is Tuesday 1 May 2007 */
echo date("m",time());
echo date("Y",time());
?>

Outputs: 30052007

The other code you posted:
<?
$time = time();
echo date("d",$time);
echo date("m",$time);
echo date("Y",$time);
?>
Doesn't suffer from that problem. It's also probably faster, but unless
you're doing it thousands of times in a loop, you won't notice any
difference.

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 23 '07 #5
NC
On Apr 23, 7:39 am, "Rolf Mander" <rolf.man...@spam.comwrote:
What performs better, theoreticaly?

echo date("d",time());
echo date("m",time());
echo date("Y",time());

Or that?

$time = time();
echo date("d",$time);
echo date("m",$time);
echo date("Y",$time);
Theoretically (and assuming that your question is more general than
the example you gave), it depends on what system resource is
constrained. If it is memory, the first would work better (there is
no additional variable required); if it is CPU, the second is better
(one function call instead of three).
when does it get relevant?
Very rarely, unless you are building something quantitative. The
resource that usually gets constained first is disk I/O.

Cheers,
NC

Apr 23 '07 #6
Rolf Mander schrieb:
What performs better, theoreticaly?
This
<?
echo date("d",time());
echo date("m",time());
echo date("Y",time());
?>
Or that?
<?
$time = time();
echo date("d",$time);
echo date("m",$time);
echo date("Y",$time);
?>
Like others already told you: The first version produces a race
condition when being run over a date change.

And perhaps you might consider using $_SERVER['REQUEST_TIME'] which
contains the timestamp of the begin of the request...

OLLi

--
Bree: "Oh, hello."
Bartender: "Hi."
Bree: "Hi. Um, I need some advice from a professional. I'd like to get
stinking drunk. Do you have anything that can accomplish that in a hurry?"
[DH 218]
Apr 23 '07 #7
While the city slept, Toby A Inkster (us**********@tobyinkster.co.uk)
feverishly typed...

[...]
It's also probably faster, but unless you're doing it
thousands of times in a loop, you won't notice
any difference.
Except, of course, if this is a web application, it is possible for
thousands of users to want to run it at the same time ;-)

Cheers,
Nige

--
Nigel Moss http://www.nigenet.org.uk
Mail address will bounce. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Apr 23 '07 #8

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

Similar topics

53
by: Paul Rubin | last post by:
I've been approached about writing a Windows app which will need a really professional looking GUI. Forget TKinter, this has to actually look good (real artists will be available to get the visual...
4
by: Theodore H. Smith | last post by:
OK, so I've invented a new data structure, used for look up tables (AKA "map" or "dictionary"), which is much faster, and uses less RAM, than the popular hashing algorithms. I've written a...
11
by: Dav risson | last post by:
hi I'm new to c# and although having read 2 tutorials I cannot find what the parenthesis in these 2 example situations mean; 1) string strKeyValue = (string)sampleConfig; 2) class myParentPage...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
12
by: EvilOldGit | last post by:
In Stroustrup he talks of a MathErr class that you can use to catch floating point exceptions. It doesn't exist, at least not in Visual C++ I can catch FP exceptions using catch(...) but am...
19
by: Mary Pegg | last post by:
There's got to be a better way: if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; if (isset($c)) echo $c."<br>"; but...
24
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
4
by: Jimmy | last post by:
Hi, The other day, my boss corrected me to use "explicit qualification" instead of using "using directive". she asked me to use : "System.Data.DataSet ds = new System.Data.DataSet();" ...
10
by: timor.super | last post by:
Hi all, Imagine I've an array of int : int anArray = new int; I want to extract all the integer that are superior to 500 I can do :
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
1
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.