In IJulia, it's about 1.8 mSec no matter how many times I run it. In the command window, it's about 57 microSeconds the second time. Why is that?
On Thursday, September 17, 2015 at 4:07:29 PM UTC-4, Elliot Saba wrote: > > Because Julia is a just-in-time compiled language, the first time you run > something, it gets compiled immediately before running it. Therefore, we > suggest you time the execution after "warming up" the JIT: > > julia> fib(n) = n < 2 ? n : fib(n-1) + fib(n-2) > fib (generic function with 1 method) > > julia> @time fib(20) > elapsed time: 0.003523425 seconds (47856 bytes allocated) > 6765 > > julia> @time fib(20) > elapsed time: 0.000144034 seconds (96 bytes allocated) > 6765 > > julia> @time fib(20) > elapsed time: 0.000143337 seconds (96 bytes allocated) > 6765 > > > Also note that the @time macro is doing the printing, so you don't need > the parentheses or the println() call for this. > > On Thu, Sep 17, 2015 at 12:53 PM, Frank Kampas <fka...@gmail.com > <javascript:>> wrote: > >> On julialang.org, it is stated that Julia is about 170 times faster than >> Mathematica for the the test "fib". I get about a factor 2. >> >> Julia: >> >> fib(n) = n < 2 ? n : fib(n-1) + fib(n-2) >> println(@time(fib(20))) >> >> elapsed time: 0.001868071 seconds (33280 bytes allocated) >> 6765 >> >> >> Mathematica: >> >> >> In[1]:= AbsoluteTiming[fib = >> Compile[{{n,_Integer}},If[n<2,n,fib[n-1]+fib[n-2]]]] >> Out[1]= {0.000134563,CompiledFunction[Argument count: 1 >> Argument types: {_Integer}]} >> >> >> >> In[2]:= AbsoluteTiming[fib[20]] >> Out[2]= {0.00385017,6765} >> >> >> >> >> >