On Thu, 2006-04-06 at 22:40, Kevin Waterson wrote:
> This one time, at band camp, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> > I'm gonna go out on a limb here and say WRONG!
> >
> > Run yourself a benchmark.
>
> benchmarks can be hazardous, but lets look at them at their most basic level.
> By this
> I mean how folks use them every day...
>
> http://www.phpro.org/benchmarks/if-switch-benchmark.html
Hazardous is right. That's a terrible benchmark. Could have eliminated
hundreds of sources of skew by running the iterations at the command
line. It even does an echos *lol*.
I ran the following as two shell scripts, 10 times each and averaged the
times to get that switch is faster by 0.000000122 secs. Big whup, as I
said in a previous post, that's very likely due to the precomputation
being assigned in userland PHP versus the internal engine. As for which
one is best, that's just flamebait -- right up there with preferred
braces style, tabs or spaces to indent, top post versus bottom post
*teehee*, etc. Personally I prefer if/elseif/else for a moderate number
of conditions or if the conditional expressions are very complex. Switch
I generally use for a large set of constants. They both have readability
pros and cons.
Cheers,
Rob.
<?php
for( $i = 0; $i < 1000000; $i++ )
{
$foo = 3;
if( $foo == 1 )
{
}
else
if( $foo == 2 )
{
}
else
if( $foo == 3 )
{
}
else
if( $foo == 4 )
{
}
else
{
}
}
?>
<?php
for( $i = 0; $i < 1000000; $i++ )
{
$foo = 3;
switch( $foo )
{
case 1:
{
break;
}
case 2:
{
break;
}
case 3:
{
break;
}
case 4:
{
break;
}
default:
{
}
}
}
?>
*Wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee* ;)
--
.------------------------------------------------------------.
| 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