Consider the following code:
zs = N /@ Range[0, 12, 10^-5];
AbsoluteTiming[bessels = BesselJ[1, #] & /@ zs;]
Length @ zs
I've tried to measure only computation of BesselJ[1, #] &
and filling of bessels
with results. What I get is:
{12.103338, Null}
1200001
So OK, 12 seconds. Now I try the same with GSL in C language and get this:
1200001 computations, time taken to compute: 0.223292 s
What's even stranger — at first I thought GSL just suffered from some accuracy problems, and thus was that fast. But when I actually compared the numbers, I found that it's Mathematica who gives worse precision, in particular for larger z
(for small z
the output is identical to GSL's). I used N[#, 100] &
as reference values.
I assume there must still be some way to achieve performance in Mathematica that is similar to that of GSL; what is this way?