My code requires to set some precision to get more accurate results. But I found when I set the precision like 20 or 30, the computation speed would jump 7-10 times slower...
Here's an example:
Block[{W = 64, d, Theta,MeshTable }, d = 2.0/W;
MeshTable =Table[{i, j}, {j, 1.0 - d/2, -1.0, -d}, {i, -1.0 + d/2, 1.0,d}];
Theta = Apply[ArcTan, MeshTable, {2}];
Table[E^(-I*q*Theta), {p, 0, 20}, {q, -p, p, 2}];] // AbsoluteTiming // First
The timing result running on my PC is 0.454783 sec.
While if I use SetPrecision:
Block[{W = 64, d, Theta}, d = 2.0/W;
MeshTable = Table[{i, j}, {j, 1.0 - d/2, -1.0, -d}, {i, -1.0 + d/2, 1.0, d}];
Theta = SetPrecision[Apply[ArcTan, MeshTable, {2}], 30];
Table[E^(-I*q*Theta), {p, 0, 20}, {q, -p, p, 2}];] // AbsoluteTiming // First
The timing would cost 3.753 sec or so.
The fact is when dealing with large numbers, the time difference is so unacceptable. I tried to use method in this thread to set the global precision instead, but still not work.
I really hope to keep the speed as best as it could after the precision set.
SetPrecisionmakes Mathematica use arbitrary-precision numbers, which use efficient but slower software routines for computing. You have to choose between machine vs. arbitrary precision. – Michael E2 May 08 '18 at 01:35