Julia script (not mine) for my today'sgretl examples.
By the way, the topic of my
first example was "recursion is slow";
it contains non-recursive version
which is thousands times faster
on 32-bit system
It seems, on 64-bit the difference
is smaller
Oleh
On Thu, 21 Jan 2016, Riccardo (Jack) Lucchetti wrote:
> On Wed, 20 Jan 2016, Allin Cottrell wrote:
>
>> Perhaps we should offer a prize for the first example of actual time-saving
>> (and/or improvement in accuracy) in sending a calculation of the sort that
>> might be required in gretl out to julia for computation.
>
> Easy: just take Oleh's recursion example.
>
> <hansl>
> set echo off
> set messages off
>
> function scalar fib(scalar n)
> return n<2 ? n : fib(n-1) + fib(n-2)
> end function
>
> set stopwatch
> eval fib(30)
> native = $stopwatch
>
> foreign language=julia
> function fib(n)
> if n<2
> return n
> else
> return fib(n-1)+fib(n-2)
> end
> end
> println(fib(30))
> end foreign
> julia = $stopwatch
>
> print native julia
> </hansl>
>
> <output>
> 832040
> 832040
>
>
> native = 71.920384
>
> julia = 4.4912745
> </output>
For sure, that's an example of something that julia does a lot faster
than gretl. But my notional prize is not yet awarded since if I insert
this native function
<hansl>
function scalar smartfib(scalar n)
if n < 2
return n
endif
scalar r5 = sqrt(5)
return (((1+r5)/2)^n - ((1-r5)/2)^n)/r5
end function
</hansl>
and time it as "native_smart", I get
<output>
832040
832040
832040
native = 35.508119
native_smart = 8.5512991e-05
julia = 0.54034932
</output>
Your example shows that recursion is a _lot_ faster in julia; so now
we want a case where recursion is actually needed.
Allin
_______________________________________________
Gretl-devel mailing list
Gretl-devel@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel