[Chicago-talk] Which "if" structure is faster?

Steven Lembark lembark at wrkhors.com
Sat Feb 21 13:53:31 CST 2004



-- Jay Strauss <me at heyjay.com>

> Hi,
>
> If I have some one time processing, then a endless loop (till the proc is
> killed).  Which is faster or are they the same:
>
> if ($firstTime) {
>     ...stuff...
>     $firstTime = 0;
> }
> else {
>     ...stuff...
> }
>
>
> or
>
>
> if (! $firstTime) {
>     ...stuff...
> }
> else {
>     ...stuff...
>     $firstTime = 0;
> }

Probably simpler to deal with it via two calls.

	sub do_something
	{
		...
	}

	do_something @first_time_args; # the first time

	for(;;)
	{
		do_something @other_time_args;
	}

--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 888 359 3508



More information about the Chicago-talk mailing list