If statements vs case
Richard Gaskin
ambassador at fourthworld.com
Mon Feb 26 15:08:03 EST 2007
Jim Ault wrote:
> So the bottom line is that if you are executing this IF or SWITCH you can
> expect to waste....
>
> Per trip cost is
>
> 89-74/10,000
> = 15/10,000 milliseconds
> = 0.0015 milliseconds
> which is 1.5 millionths of a second longer per loop to use IF
>
> A million here, a million there, and pretty soon your talking real seconds
> :-)
>
> Thanks for the testing work.
Fortunately not much effort since my script editor inserts an outline of
benchmarking scripts in a single keystroke, and I was benchmarking some
other project-related stuff here this morning.
I rarely benchmark much at all these days because Rev's so fast it
usually doesn't matter. As in this case, we're talking tiny fractions
of a millisecond, which is commonly the sort of differences I find
between alternate ways of doing things in Rev once you avoid the basics
like keeping data out of fields when doing calculations on it.
But that said, I have a couple applications that are quite feature-rich,
and some of these features require that the app be as responsive as
possible. Like you say, if a routine is called frequently enough to add
up to even tenths of seconds then performance will become noticeably
different.
And with these more complex apps, often I don't know today what features
I'll be asked to add next year, so if I optimize code now I have less to
worry about when the next set of feature requests comes in.
The exercise also illustrated another benefit of switch over if-then:
it took a couple of tries to get the logic of the if-then to do what it
needed to, while logic of a switch blocks is often more self-evident to
read.
--
Richard Gaskin
Fourth World Media Corporation
___________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list