Re: [PHP] What is faster?

2005-06-06 Thread Mark Cain
I see your point about including the timing code in the calculation itself
and while it does add time to the process, he is not just timing this
code -- he is timing this code against another.  Meaning we don't want to
know How fast is this code? per se -- we want to know Which is faster?
So, arguably from the faster point of view, as long as the time mech is in
both tests, the question will be answered with a degree of certainty.  From
the days of my boyhood, even if the race route were two times around the
big oak tree, the faster runner would still win the race.

Question for you, please:

In your post you say:

 time. For example, using something like ab will let you test your code
 in its raw form - without the timing and looping.

What is ab?  I am somewhat limited in my depth and scope of php and so I
have never seen this before.  Care to point me in a direction where I could
learn more?

Mark Cain




- Original Message -
From: Chris Shiflett [EMAIL PROTECTED]
To: Mark Cain [EMAIL PROTECTED]
Cc: Andy Pieters [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Sunday, June 05, 2005 9:56 PM
Subject: Re: [PHP] What is faster?


 Mark Cain wrote:
  I checked the first expression with 1,000 iterations and it
  took 0.00745 seconds.
 
  Here is the code I used.

 [snip]

  $start1 = vsprintf('%d.%06d', gettimeofday());

 Although many would argue that it's pointless to worry over such small
 details (and they have valid arguments), it's better to construct your
 benchmark so that the timing mechanism impacts your code as little as
 possible.

 Although consistency is difficult to achieve without some effort, you
 can at least get your timing mechanism out of the code that you want to
 time. For example, using something like ab will let you test your code
 in its raw form - without the timing and looping.

 I also dislike unit tests that are part of the code they're meant to
 test. :-)

 Hope that helps.

 Chris

 --
 Chris Shiflett
 Brain Bulb, The PHP Consultancy
 http://brainbulb.com/



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



Re: [PHP] What is faster?

2005-06-06 Thread Jochem Maas

Mark Cain wrote:

I see your point about including the timing code in the calculation itself
and while it does add time to the process, he is not just timing this
code -- he is timing this code against another.  Meaning we don't want to
know How fast is this code? per se -- we want to know Which is faster?
So, arguably from the faster point of view, as long as the time mech is in
both tests, the question will be answered with a degree of certainty.  From
the days of my boyhood, even if the race route were two times around the
big oak tree, the faster runner would still win the race.

Question for you, please:

In your post you say:



time. For example, using something like ab will let you test your code
in its raw form - without the timing and looping.



What is ab?  I am somewhat limited in my depth and scope of php and so I
have never seen this before.  Care to point me in a direction where I could
learn more?


apache benchmark, try:

 man ab

on your local linux cmd line (assuming you have apache installed)



Mark Cain




- Original Message -
From: Chris Shiflett [EMAIL PROTECTED]
To: Mark Cain [EMAIL PROTECTED]
Cc: Andy Pieters [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Sunday, June 05, 2005 9:56 PM
Subject: Re: [PHP] What is faster?




Mark Cain wrote:


I checked the first expression with 1,000 iterations and it
took 0.00745 seconds.

Here is the code I used.


[snip]



$start1 = vsprintf('%d.%06d', gettimeofday());


Although many would argue that it's pointless to worry over such small
details (and they have valid arguments), it's better to construct your
benchmark so that the timing mechanism impacts your code as little as
possible.

Although consistency is difficult to achieve without some effort, you
can at least get your timing mechanism out of the code that you want to
time. For example, using something like ab will let you test your code
in its raw form - without the timing and looping.

I also dislike unit tests that are part of the code they're meant to
test. :-)

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/







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



Re: [PHP] What is faster?

2005-06-06 Thread Marek Kilimajer

Mark Cain wrote:

I see your point about including the timing code in the calculation itself
and while it does add time to the process, he is not just timing this
code -- he is timing this code against another.  Meaning we don't want to
know How fast is this code? per se -- we want to know Which is faster?


You want to also know which one parses faster

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



[PHP] What is faster?

2005-06-05 Thread Andy Pieters
Hi all

Of these two expressions, which one is faster?

if(!(is_null($customMenu))  (is_array($customMenu)))
  $menu=$customMenu;
 else
 $menu=array('Documentation','Settings');


OR

$menu=(!(is_null($customMenu))  (is_array($customMenu))?$customMenu:$menu);

Anybody have any documentation on this?


Kind regards


Andy

-- 
Registered Linux User Number 379093
-- --BEGIN GEEK CODE BLOCK-
Version: 3.1
GAT/O/E$ d-(---)+ s:(+): a--(-)? C$(+++) UL$ P-(+)++
L+++$ E---(-)@ W++$ !N@ o? !K? W--(---) !O !M- V-- PS++(+++)
PE--(-) Y+ PGP++(+++) t+(++) 5-- X++ R*(+)@ !tv b-() DI(+) D+(+++) G(+)
e$@ h++(*) r--++ y--()
-- ---END GEEK CODE BLOCK--
--
Check out these few php utilities that I released
 under the GPL2 and that are meant for use with a 
 php cli binary:
 
 http://www.vlaamse-kern.com/sas/
--

--

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



Re: [PHP] What is faster?

2005-06-05 Thread Mark Cain
I checked the first expression with 1,000 iterations and it took 0.00745
seconds.

Here is the code I used.  You can use it find the time for the second
expression and any future which is faster queries you might have.  This
way you can create you own documentation.


?
$start1 = vsprintf('%d.%06d', gettimeofday());


for($i=1;$i=1000;$i++){
if(!(is_null($customMenu))  (is_array($customMenu))) {
  $menu=$customMenu;
} else {
$menu=array('Documentation','Settings');
};
}

$end1 = vsprintf('%d.%06d', gettimeofday());

$lapse1 = bcsub($end1,$start1,7);

echo Start Time:  . $start1 . BR . End Time:  . $end1 . P .
$lapse1;
?




Mark Cain


- Original Message -
From: Andy Pieters [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Sunday, June 05, 2005 12:24 PM
Subject: [PHP] What is faster?


 Hi all

 Of these two expressions, which one is faster?

 if(!(is_null($customMenu))  (is_array($customMenu)))
   $menu=$customMenu;
  else
  $menu=array('Documentation','Settings');


 OR

 $menu=(!(is_null($customMenu)) 
(is_array($customMenu))?$customMenu:$menu);

 Anybody have any documentation on this?


 Kind regards


 Andy

 --
 Registered Linux User Number 379093
 -- --BEGIN GEEK CODE BLOCK-
 Version: 3.1
 GAT/O/E$ d-(---)+ s:(+): a--(-)? C$(+++) UL$ P-(+)++
 L+++$ E---(-)@ W++$ !N@ o? !K? W--(---) !O !M- V-- PS++(+++)
 PE--(-) Y+ PGP++(+++) t+(++) 5-- X++ R*(+)@ !tv b-() DI(+) D+(+++) G(+)
 e$@ h++(*) r--++ y--()
 -- ---END GEEK CODE BLOCK--
 --
 Check out these few php utilities that I released
  under the GPL2 and that are meant for use with a
  php cli binary:

  http://www.vlaamse-kern.com/sas/
 --

 --

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



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



Re: [PHP] What is faster?

2005-06-05 Thread Robert Cummings
On Sun, 2005-06-05 at 12:24, Andy Pieters wrote:
 Hi all
 
 Of these two expressions, which one is faster?
 
 if(!(is_null($customMenu))  (is_array($customMenu)))
   $menu=$customMenu;
  else
  $menu=array('Documentation','Settings');
 
 
 OR
 
 $menu=(!(is_null($customMenu))  (is_array($customMenu))?$customMenu:$menu);
 
 Anybody have any documentation on this?

I didn't bother checking for you but I do know that:

$customMenu !== null

Is about 3 or 4 times faster than

!is_null( $customMenu )

Function calls are always much slower than operators.

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



Re: [PHP] What is faster?

2005-06-05 Thread Chris Shiflett

Mark Cain wrote:

I checked the first expression with 1,000 iterations and it
took 0.00745 seconds.

Here is the code I used.


[snip]


$start1 = vsprintf('%d.%06d', gettimeofday());


Although many would argue that it's pointless to worry over such small 
details (and they have valid arguments), it's better to construct your 
benchmark so that the timing mechanism impacts your code as little as 
possible.


Although consistency is difficult to achieve without some effort, you 
can at least get your timing mechanism out of the code that you want to 
time. For example, using something like ab will let you test your code 
in its raw form - without the timing and looping.


I also dislike unit tests that are part of the code they're meant to 
test. :-)


Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

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