Re: [PHP] Re: 1 last error to fix before the application is done!



On Tue, Oct 14, 2008 at 10:29 AM, Colin Guthrie <gmane@xxxxxxxxxxxxxx> wrote:
Andrew Ballard wrote:

I've heard that a lot, but I just don't see it. I'm sure some of you
can come up with better tests than this, but here is what I used:

...

Based on these results, I'd hardly use the "language construct versus
function call" optimization argument to make my decision. I'm not sure
if this is a testament to improvements in the PHP engine over the last
couple years, or if equipment has gotten fast enough that the
differences have become irrelevant. Quite possibly, it's both.

There are a couple of issues with those benchmarks...
1. It uses rand()... this is generally a bad thing in benchmarks

True. I'm not sure how to test it, but I'm curious if there is a bias
toward elements that do or do not exist, so I let it pick values both
in and out of range. I suppose I could have preselected values to be
consistent among all tests.

2. It uses internal (wall clock) timing and tests different things in the
same application run.

I'm on a Windows development machine.

3. 50k iterations is easy! Give it something hard :)

I've done the same with 100k or more. The average is the same. If I'm
ever calling either of these functions 100k times in a production
script, I need to rethink the app anyway.

You should really use an external timing function (like "time blah" on *nix)
as it shows you real processor time used, as well as wall-clock time.

Again, I'm on Windows and my PHP environment is inside Zend Studio. Is
this something I can see with something like the profiler in Xdebug?
(I have run similar test scripts on the web servers, but they are also
running Windows and I don't have access other than file shares to
where we publish apps.)

I've posted a simple benchmark else where on this thread that tests which
prove that for a two index-depth test, !empty is approx 4.5x faster than the
equiv array_key_exists tests.

I saw that, and for this case I'd agree with you. To be fair, I think
the savings is more due to the difference between calling empty() once
to get the desired result versus calling array_key_exists() twice and
then testing the actual array value (which I'm sure means scanning the
array to get the value and then doing a logical comparison). I will,
however, file this information for later use as it looks useful in
some situations like this one.

Even for a single depth array test, I still get ~3x speed improvement using
empty() vs. array_key_exists().


Andrew
.



Relevant Pages

  • Re: Spyware/Recycle Bin Help
    ... I must have some kind of spyware, adware or a virus of ... I try to empty it and it makes the crumbling paper ... What to Know Before You Download and Install Windows XP Service Pack 2 ... Why you should use a computer firewall.. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Explorer crashes at least once all the time
    ... Do you really want to trust someone that was banned from posting ... And do you really want to trust someone that has had to change their ... Calling an illegal alien an "undocumented worker" is like calling a ... A .dll file is a special type of Windows program ...
    (microsoft.public.windowsxp.general)
  • RE: Internet Connection Wizard failing at Firewall Config and Secu
    ... Enhanced Security Configuration from Add/Remove Windows Components to ... | calling CNetCommit::ValidateFulltimeConnectionProperties. ... | Call to Reading web publishing selection returned ok. ... | Call to Configuring for fulltime connection returned ok. ...
    (microsoft.public.windows.server.sbs)
  • Re: Windows Server 2003 SP2 causes CEICW to fail?
    ... During my server reboot at lunch time today, I noticed that when windows ... restarted it came up with an error message saying that CEICW was blocked ... calling CRFireCommit::ValidatePropertyBag. ... Call to Reading web publishing selection returned ok. ...
    (microsoft.public.windows.server.sbs)
  • Re: Creating a C++ like message loop in .NET threaded classes.
    ... Just grab your good ol' C++ message loop knowledge and write the same code in .NET, calling API functions such as GetMessage and DispatchMessage through P/Invoke. ... control over Windows message processing (or maybe it's in the .NET and I ... Now I don't necessarily want the code of these members ... the object processes the message when its thread is ...
    (microsoft.public.dotnet.framework)