-jn- wrote:
If speed is the objective (rather than total correctness ;-) one
could write:
fib2: func [first second n] [
either n > 0 [
fib2 second first + second n - 1
][
first
]
]
placing the "most likely" branch first. This rearrangement saves
just over 25%, according to my quick-and-dirty benchmarking:
>> x: now/time loop 10000 [y: fib 1.0 1.0 100] now/time - x
== 0:01:37
>> x: now/time loop 10000 [y: fib 1.02 1.0 100] now/time - x
== 0:01:12
.....
The speed-up seemed unbelievable to me (placing the most probable case of
EITHER first shouldn't have any influence on speed in this case) and I made
my own computations. The times were exactly the same with the same data here
>> System/version
== 2.2.0.3.1
Ladislav