Re: test valid

new topic     » goto parent     » topic index » view thread      » older message » newer message

Jean Hendrickx wrote:
>I wished to optimize a test that find a value in a sequence of valid
>numbers. I wondered that the third test was the fastest though it seems
>to be poor programming. Following the tests and results.
>Any advice or comment is welcome.
> <SKIPPED>
>-- Test 1 with or ---------------------------
> <SKIPPED>
>-- Test 2 with find --------------------------
> <SKIPPED>
>-- Test 3 with if-elsif -----------------------
> <SKIPPED>
>-- Results (PC 486 DX2 80 Mhz):
>-- search for 1 :  or -> 1.21 sec   find -> 0.95 sec     elsif ->  0.42 sec
>-- search for 3 :        1.28               0.85                   0.30
>-- search for 5 :        1.28               0.90                   0.39
>-- search for 7 :        1.29               0.95                   0.47
>-- search for 11:  or -> 1.30 sec   find -> 1.01 sec     elsif ->  0.51 sec
>--
>-- Jean.Hendrickx. j.hendrickx at infoboard.be

     The or test results make sense, since Euphoria doesn't use short
circuit evaluation (i.e. it doesn't stop evaluating expressions just because
the total expression's result is already certain, it *always* evaluates the
entire conditional, at least as far as my own experiments have shown).
Therefore they *should* be slower than a find() call since the find call
will presumably drop out and return a value as soon as it finds the value.
The or'ing method should also have less time variation(same reason), which
does seem to be the case in your test results.
     The elsif results, however, are definitely weird.  I can see how they
would be faster in *some* cases since they would find a true condition, do
their thing, and drop out without further testing.   But you are right, it
is certainly odd that the worst-case elsif should still be faster than
either of the other methods.

     Any suggestions, gurus?

Craig

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu