For further reading, I suggest you check out the the performance section
<http://julia.readthedocs.org/en/release-0.4/manual/performance-tips/> of
the manual; it explains all this and more.  Welcome to Julia, and because
many of these micro benchmarks can be highly dependent on system
configuration (what CPU features you have, what operating system you're on,
what version of MATLAB/Mathematica you are comparing against) I highly
recommend coming up with benchmarks that are specific to your use case,
consulting the performance tips section of the manual when you run into a
problem, and then mailing this list if you are still seeing suboptimal
performance.  Writing high performance code in Julia isn't automatic, but
we do strive to make it as easy as possible.
-E

On Thu, Sep 17, 2015 at 1:06 PM, Shashi Gowda <shashigowd...@gmail.com>
wrote:

> The first time you run a function with a certain tuple of types of
> arguments it gets just-in-time compiled adding to the time you measure.
> Subsequent runs will be faster and allocate much less memory. Try:
>
> fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
> @time(fib(20))
> @time(fib(20))
>
> and consider the second result.
>
>
> On Fri, Sep 18, 2015 at 1:23 AM, Frank Kampas <fkam...@gmail.com> 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}
>>
>>
>>
>>
>>
>

Reply via email to