Re: [PHP] Benchmarking check to see if array key is set

2007-11-08 Thread Peter Ford
Ford, Mike wrote:
 On 06 November 2007 12:57, Christoph Boget wrote:
 
 Consider the following test code:
 
 [...snip...]
  
 Running that I found that

 if( isset( $myArray[$key] ))

 is faster than

 if( array key exists( $key, $myArray ))

 is faster than

 if( $myArray[$key] )

 To be honest, I was surprised.  I would have thought that if(
 $myArray[$key] ) would have been the fastest way to check.  I'm
 wondering if those in the know could explain why it's the slowest and
 also where the discrepancies come from w/r/t the difference in the
 amount of time it takes 
 to make each
 check.
 
 OK, I'll take a stab.
 
 Firstly, isset() is a language construct not an actual function, so the only 
 thing your isset() does is check whether the array element exists.
 
 Next, array_key_exists() is the only one that involves a real function call, 
 so it's going to bear that cost. However, the function then does a pretty 
 simple test which again only involves checking whether the key exists, so the 
 function itself is going to be pretty quick.
 
 Finally, the if() is the only one that actually gets the value in 
 $myArray[$key], and then casts it to Boolean to boot, and the cost of this 
 must therefore outweigh the cost of a function call plus a check for a key's 
 existence.
 
 I'm certainly not surprised that isset() is the quickest, because it does the 
 simplest test, but to be honest I'm not sure if I'd have predicted the 
 relative positions of the other two..
 
 Cheers!
 
 Mike
 

For convenience let's label the cases:
1: if( isset( $myArray[$key] ))
2: if( array key exists( $key, $myArray ))
3: if( $myArray[$key] )

Now, surely 3 is not comparable at all to 1 and 2.
Cases 1 and 2 check that the key exists in the array.
Case 3 does a boolean test on the value referenced by the key. That has several
consequences:
Firstly, if there is no element with key $key in the arrray, the interpreter
will throw an error (undefined index ...); this error could be suppressed and
ignored, I suppose.
Secondly, if the value referenced by the key is equivalent to FALSE, then the
test will return FALSE; for example, if you have set $myArray[$key]='' or
$myArray[$key]=0. This could be very confusing.

So if you want to test that the key exists, case 3 is NOT the way to do it. In
fact, you will often want to check that the key exists(with case 1, ideally)
BEFORE using a test of the form of case 3.

Cheers
Pete Ford (no relation, I think, although I do have a cousin called Michael...)

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



[PHP] Benchmarking check to see if array key is set

2007-11-06 Thread Christoph Boget
Consider the following test code:

?php
  $myArray = array();
  for( $i = 0; $i = 1; $i++ )
  {
$date = microtime( TRUE );
$key  = rand( $date, $date * rand( 1, 5000 ));
$myArray[$key] = $key;

  }
  echo '$myArray items created: ' . count( $myArray ) . 'brbr';

  $startTime = microtime( TRUE );
  $foundCount = 0;
  for( $i = 0; $i = 1; $i++ )
  {
$date = microtime( TRUE );
$key  = rand( $date, $date * rand( 1, 5000 ));
if( array key exists( $key, $myArray ))
{
  $foundCount++;

}
  }
  $endTime = microtime( TRUE );
  echo 'array key exists took [' . ( $endTime - $startTime ) . '] seconds;
found: [' . $foundCount . '] keysbrbr';

  $startTime = microtime( TRUE );
  $foundCount = 0;
  for( $i = 0; $i = 1; $i++ )
  {
$date = microtime( TRUE );
$key  = rand( $date, $date * rand( 1, 5000 ));
if( isset( $myArray[$key] ))
{
  $foundCount++;

}
  }
  $endTime = microtime( TRUE );
  echo 'isset took [' . ( $endTime - $startTime ) . '] seconds; found: [' .
$foundCount . '] keysbrbr';

  $startTime = microtime( TRUE );
  $foundCount = 0;
  for( $i = 0; $i = 1; $i++ )
  {
$date = microtime( TRUE );
$key  = rand( $date, $date * rand( 1, 5000 ));
if( $myArray[$key] )
{
  $foundCount++;

}
  }
  $endTime = microtime( TRUE );
  echo 'IF() took [' . ( $endTime - $startTime ) . '] seconds; found: [' .
$foundCount . '] keysbrbr';
?

Running that I found that

if( isset( $myArray[$key] ))

is faster than

if( array key exists( $key, $myArray ))

is faster than

if( $myArray[$key] )

To be honest, I was surprised.  I would have thought that if( $myArray[$key]
) would have been the fastest way to check.  I'm wondering if those in the
know could explain why it's the slowest and also where the discrepancies
come from w/r/t the difference in the amount of time it takes to make each
check.

thnx,
Chris


RE: [PHP] Benchmarking check to see if array key is set

2007-11-06 Thread Ford, Mike
On 06 November 2007 12:57, Christoph Boget wrote:

 Consider the following test code:

[...snip...]
 
 Running that I found that
 
 if( isset( $myArray[$key] ))
 
 is faster than
 
 if( array key exists( $key, $myArray ))
 
 is faster than
 
 if( $myArray[$key] )
 
 To be honest, I was surprised.  I would have thought that if(
 $myArray[$key] ) would have been the fastest way to check.  I'm
 wondering if those in the know could explain why it's the slowest and
 also where the discrepancies come from w/r/t the difference in the
 amount of time it takes 
 to make each
 check.

OK, I'll take a stab.

Firstly, isset() is a language construct not an actual function, so the only 
thing your isset() does is check whether the array element exists.

Next, array_key_exists() is the only one that involves a real function call, so 
it's going to bear that cost. However, the function then does a pretty simple 
test which again only involves checking whether the key exists, so the function 
itself is going to be pretty quick.

Finally, the if() is the only one that actually gets the value in 
$myArray[$key], and then casts it to Boolean to boot, and the cost of this must 
therefore outweigh the cost of a function call plus a check for a key's 
existence.

I'm certainly not surprised that isset() is the quickest, because it does the 
simplest test, but to be honest I'm not sure if I'd have predicted the relative 
positions of the other two.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
JG125, The Headingley Library,
James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730  Fax:  +44 113 812 3211 


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] Benchmarking SPL Iterators vs for / foreach ???

2005-11-27 Thread Curt Zirzow
On Sat, Nov 26, 2005 at 02:36:26PM +0200, Andrei Verovski (aka MacGuru) wrote:
 Hi,
 
 Someone have benchmarked SPL iterators vs for / foreach loops? What is the 
 performance penalty?
 
 SPL is �interpreted wrapper� on the top of C++ STL (correct me if I am 
 wrong), and I am sure it uses STL callbacks. But unlike C++, PHP scripts are 
 interpreted, so pointer arithmetic will work only through Zend engine which 
 for sure  adds extra performance penalty.
 
I think you're confused at what SPL is in php:

http://php.net/spl

Curt.
-- 
cat .signature: No such file or directory

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



[PHP] Benchmarking SPL Iterators vs for / foreach ???

2005-11-26 Thread Andrei Verovski (aka MacGuru)
Hi,

Someone have benchmarked SPL iterators vs for / foreach loops? What is the 
performance penalty?

SPL is ¨interpreted wrapper¨ on the top of C++ STL (correct me if I am wrong), 
and I am sure it uses STL callbacks. But unlike C++, PHP scripts are 
interpreted, so pointer arithmetic will work only through Zend engine which for 
sure  adds extra performance penalty.

Thanks in advance for any suggestion(s)



***   with best regards 
***   Andrei Verovski (aka MacGuru)
***   Mac, Linux, DTP, Programming Web Site
***
***   http://snow.prohosting.com/guru4mac/


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



RE: [PHP] Benchmarking a script

2004-09-14 Thread Gryffyn, Trevor
You will still get the benchmark of the functions, you just declare them
outside of your benchmarking loop so they don't get re-declared.

Pardon my syntax, I'm just going to try to demonstrate (using the
getmicrotime function from the PHP manual):

?php

Function dosomething ($somevar) {
echo $somevar;
return 1;
}

Function dosomethingelse ($somevar) {
echo $somevar;
return 1;
}

function getmicrotime() 
{ 
list($usec, $sec) = explode( , microtime()); 
return ((float)$usec + (float)$sec); 
} 


# Benchmark here
$time_start = getmicrotime();
For ($i=0; $i = 10; $i++) {
  $retval = dosomething($i);
  $retval2 = dosomethingelse($i);
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
# end benchmarking
?


Every time you call dosomething and dosomethingelse, it executes the
function, it just doesn't delare it over again.  So even though your
functions are declared outside of your benchmark loop, they still get
executed inside the loop, therefore you get the time needed to execute
100,000 calls of both functions (in this case).

The only thing you're not benchmarking here is the time to declare the
functions once, which is extremely minimal.

Does that clarify it a bit for you?

-TG

 -Original Message-
 From: Cristian Lavaque [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, September 14, 2004 1:18 PM
 To: Gryffyn, Trevor
 Subject: Re: [PHP] Benchmarking a script
 
 
 Hello Trevor,
 
 I really appreciate your reply! In fact I haven't found a way 
 to do it 
 yet. I can't really do it the way you suggest cause part of 
 what I want 
 to benchmark is defining the functions. Someone suggested benching it 
 from Apache, but I'm not sure how to do that. Thank you very much for 
 taking the time to drop me an email. :)
 
 Regards,
 Cristian
 
 Gryffyn, Trevor wrote:
  Doesn't look like anyone responded to this (publicly at least).  I
  wasn't sure if you were still having a problme, but 
 something you might
  try is putting the function definitions outside of the 
 loop.  They'll
  get called once, and still be executed within the loop.
  
  Good luck!
  
  -TG
 
 __
 _
 This message has been checked by mks_vir mail scanner ( 
http://www.mks.com.pl )

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



[PHP] Benchmarking a script

2004-06-23 Thread Anguz
Hello,
I have a script I am optimizing and want to compare the before and after 
in speed. So I wrote a few lines to loop this script but I have a 
problem. In the script I'm optimizing there's some function definitions 
and when the script starts the second iteration it throws an error 
because the function already exists. How can I modify my benchmark code 
to make it work? This is what I have:

?php
$bench_n = 1000;
for($bench_i=$bench_n; --$bench_i=0; ){
ob_start();
$bench_time1 = array_sum(explode(' ', microtime()));
// script start 
// script...
	// script end **
	$bench_time0 += array_sum(explode(' ', microtime())) - $bench_time1;
	while(@ob_end_clean());
}
echo 'preTot Time: ' , $bench_time0 , 'br /Loops:' , $bench_n , 
'br /Avg Time: ' , ($bench_time0 / $bench_n) , '/pre';
?

Thank you very much in advance.
Cristian
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Benchmarking PHP vs ASP.net

2003-09-08 Thread Sid
Hello,

Many people ask me if ASP.net is faster than PHP. I know for a fact that it is 
(because PHP is not optimized).
But then what about optimized PHP and compiled ASP.net. This would be a fairer 
comparison in my opinion. Anyone seen any benchmarks of this? If so please let me know 
as I would not like to pass on any wrong info.

Thanks

- Sid

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



RE: [PHP] Benchmarking PHP vs ASP.net

2003-09-08 Thread Angelo Zanetti
Apparently if you read the terms of agreement when installing .NET you can't
publish your benchmarking results without their permission.

just a thought.

would be interesting to see comparison, and maybe also JSP, cold fusion

-Original Message-
From: Sid [mailto:[EMAIL PROTECTED]
Sent: Monday, September 08, 2003 2:17 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Benchmarking PHP vs ASP.net


Hello,

Many people ask me if ASP.net is faster than PHP. I know for a fact that it
is (because PHP is not optimized).
But then what about optimized PHP and compiled ASP.net. This would be a
fairer comparison in my opinion. Anyone seen any benchmarks of this? If so
please let me know as I would not like to pass on any wrong info.

Thanks

- Sid

--
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] Benchmarking PHP vs ASP.net

2003-09-08 Thread Jay Blanchard
[snip]
Many people ask me if ASP.net is faster than PHP. I know for a fact that
it is (because PHP is not optimized).
But then what about optimized PHP and compiled ASP.net. This would be a
fairer comparison in my opinion. Anyone seen any benchmarks of this? If
so please let me know as I would not like to pass on any wrong info.
[/snip]

As has been mentioned several times, comparing ASP.net (or 'plain' ASP)
to PHP is comparing apples and oranges unless you are comparing the
processing engine itself. In this day and age where processor power is
what it is and growing according to Moore, speed comparisons are
basically fodder for smirking 'my server can beat up your server'.

Let's say I have a database with 1 million records. I need to update
10,000 of those records. On the same server code supported by ASP.net
runs in 1.032 seconds while code in PHP runs in 1.067 seconds. OMG! PHP
is slower. The difference is .035 seconds. Does this matter? Who is
asking which is faster? Why do they care? Are they looking for a reason
to choose one technology over another?

Since ASP.net namespaces are compiled that creates a fundamental
difference when comparing to PHP. What language are you using to create
the ASP.net namespace? 

All in all I think it a waste to even entertain a resposnse to folks who
would ask this question other than to say 'a comparison between these
technologies is impossible due to the differences'.

Have a pleasant and productive day.

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



RE: [PHP] Benchmarking PHP vs ASP.net

2003-09-08 Thread Sid
 Apparently if you read the terms of agreement when installing .NET
 you can't publish your benchmarking results without their
 permission.

Is Micro$oft©® scared of being beaten? Now I am going to get the benchmarking results 
by hook or crook! Now I HATE M$. aahh!!

I've seen a comparison of JSP PHP and CF (Don't remember where - All I know is that it 
came up among the top results in google for I think 'ASP.net vs PHP')

- Sid

On Mon, 08 Sep 2003 14:25:20 +0200, Angelo Zanetti wrote:
 Apparently if you read the terms of agreement when installing .NET
 you can't publish your benchmarking results without their
 permission.

 just a thought.


 would be interesting to see comparison, and maybe also JSP, cold
 fusion


 -Original Message-
 From: Sid [mailto:[EMAIL PROTECTED]
 Sent: Monday, September 08, 2003 2:17 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Benchmarking PHP vs ASP.net


 Hello,


 Many people ask me if ASP.net is faster than PHP. I know for a fact
 that it is (because PHP is not optimized).
 But then what about optimized PHP and compiled ASP.net. This would
 be a fairer comparison in my opinion. Anyone seen any benchmarks of
 this? If so please let me know as I would not like to pass on any
 wrong info.

 Thanks


 - Sid


 --
 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] Benchmarking PHP vs ASP.net

2003-09-08 Thread Dan Anderson
  OMG! PHP
 is slower. The difference is .035 seconds. Does this matter? Who is
 asking which is faster? Why do they care? Are they looking for a reason
 to choose one technology over another?

Throw In 2 Cents 

I totally agree with you, but I find it funny that many times when
talking to people they don't seem to realize that unless you are talking
about an enterprise solution for a Fortune 500 company, it is the
/developer/ time that costs the most.  So let's assume a developer can
get a solution done in PHP in a weeks worth of work and in ASP.net for 2
weeks.  Then you have spent enough to buy a second server for redundancy
on a solution that is .035 seconds faster.

But hey, I don't complain much.  It keeps me employed.

/Throw In 2 Cents 

-Dan

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



Re: [PHP] Benchmarking PHP vs ASP.net

2003-09-08 Thread Raditha Dissanayake
Can't resist trowing in my 0.02 either:

As dan pointed out it's so much faster to do things in php. When you 
take into consideration the fact that code on windows never work  the 
way it's supposed you are saving a lot of man hours.

Second point worth mentioning is that a given languages/frameworks will 
be faster at certains tasks while slower at another task. Thus as jay 
has explained generic benchmarks are realy of little significance.

Dan Anderson wrote:

OMG! PHP
is slower. The difference is .035 seconds. Does this matter? Who is
asking which is faster? Why do they care? Are they looking for a reason
to choose one technology over another?
   

Throw In 2 Cents 

I totally agree with you, but I find it funny that many times when
talking to people they don't seem to realize that unless you are talking
about an enterprise solution for a Fortune 500 company, it is the
/developer/ time that costs the most.  So let's assume a developer can
get a solution done in PHP in a weeks worth of work and in ASP.net for 2
weeks.  Then you have spent enough to buy a second server for redundancy
on a solution that is .035 seconds faster.
	But hey, I don't complain much.  It keeps me employed.

/Throw In 2 Cents 

-Dan

 



--
http://www.radinks.com/upload
Drag and Drop File Uploader.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Benchmarking PHP vs ASP.net

2003-09-08 Thread Chris Shiflett
--- Sid [EMAIL PROTECTED] wrote:
 Many people ask me if ASP.net is faster than PHP. I know for a fact
 that it is (because PHP is not optimized).

Don't be so easily fooled by hollow terms.

Go here:

http://public.yahoo.com/~radwin/talks/yahoo-phpcon2002.htm

Start with the slide entitled Benchmarking PHP. You'll see PHP perform against
yScript2, the second generation of Yahoo!'s proprietary C/C++ engine, and YSP,
an extremely fast mod_perl based solution.

Why bother comparing PHP to ASP in terms of performance when it can compete
with the performance of two of the fastest engines in the world? People don't
choose ASP for performance.

Here is another benchmark:

http://www.chamas.com/bench/index.html

If you want some opinions on how the languages compare, search Google. Here is
a link I found:

http://www.netconcepts.com/news/php_vs_asp.php

 I've seen a comparison of JSP PHP and CF (Don't remember where -
 All I know is that it came up among the top results in google for
 I think 'ASP.net vs PHP')

Yes, PHP was the top performer and ColdFusion was the easiest to develop in.

Lastly, ASP ties you to a particular platform, and a particularly bad one at
that.

Choose ASP if you're an NBM shop. Choose mod_perl if you really need that
fractional increase in speed. Choose PHP if you like it. Choose JSP if you're
really into Java and think complaints about its performance are unfounded.
Choose ColdFusion if you can write HTML and think that qualifies you as a Web
developer. Most importantly, don't choose a language based on what someone on a
mailing list tells you. :-)

Hope that helps.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/

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



[PHP] Benchmarking

2003-03-25 Thread reven
Hi,

I've been making a web ap PHP based, but I fear the number of arrays it has
is too big. Is there any way to benchmark a script, or are there any
recomendations or standards about how much time execution takes and how many
resources it takes?

Thanks,

Reven



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



RE: [PHP] Benchmarking

2003-03-25 Thread John W. Holmes
 I've been making a web ap PHP based, but I fear the number of arrays
it
 has
 is too big. Is there any way to benchmark a script, or are there any
 recomendations or standards about how much time execution takes and
how
 many
 resources it takes?

The benchmarking is just a matter of subtracting the time at the end of
your script from the time at the beginning.

Check your web server logs for the resources question. I don't know of
any PHP way to do it. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



[PHP] benchmarking used memory

2003-01-13 Thread peio popov
	Hi,
I would like to know if there is way to measure how much memory a script uses during execution.
Althought threre is no such function in the manual,  in my opinion there must be some indication how much memory is used 
because of the memory_limit directive in the php.ini file. So if php is able to determine the maximum level it should be
able and to give indication and for the actual.

	Thanks in advance
	Peio Popov	
--

---
Peio Popov - [EMAIL PROTECTED]
icq# 117130734
http://www.cilaw.org


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



[PHP] php benchmarking suite

2002-07-23 Thread George Schlossnagle

Is anyone aware of a php benchmarking suite comparable in functionality 
to perls Benchmark.pm?

// George Schlossnagle
// Principal Consultant
// OmniTI, Inc  http://www.omniti.com
// (c) 240.460.5234   (e) [EMAIL PROTECTED]
// 1024D/1100A5A0  1370 F70A 9365 96C9 2F5E 56C2 B2B9 262F 1100 A5A0


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




[PHP] Benchmarking a site...

2002-07-11 Thread Rodolfo Gonzalez

Hi,

is it possible to benchmark a site/page which uses authentication via PHP 
sessions?. If so, could you please tell me some hints to do it?.

Thank you.
Rodolfo.



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




RE: [PHP] Benchmarking a site...

2002-07-11 Thread John Holmes

 is it possible to benchmark a site/page which uses authentication via
PHP
 sessions?. If so, could you please tell me some hints to do it?.

Why does it matter if the page is authenticated? Get the time at the
beginning, the time at the end of the page, subtract smaller from
larger, and you've got how long it took the page to be created I
think PEAR has a module that provides a nice interface for doing this
and I'm sure there are others.

---John Holmes...


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




[PHP] benchmarking php scripts

2002-01-16 Thread Eugene Lee

Is there a way to benchmark a PHP script to see how intensive it is?
For example, execution time, CPU/RAM/disk usage, etc.  Thanks in advance.


-- 
Eugene Lee
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]