I want to calculate a loop. For speed, I compiled my code. Even after the compilation, it is still very slow in getting the results.
Are there any further improvements that can be made to my code?
Needs["CCompilerDriver`"]
c =
Compile[{{x0, _Integer}},
With[{x = x0},
pover = 0.0; t = 1.0;
While[t <= x - 1,
pover =
pover +
Total[
Table[
1.0/Sqrt[a^2 + t^2 + (100000.0 - 0.7)^2] -
1.0/Sqrt[a^2 + t^2 + (100000.0 + 0.7)^2],
{a, t + 1, 40000.0,1}]];
t++];
pover],
CompilationTarget -> "C",
Parallelization -> True,
RuntimeOptions -> "Speed"]`
Timing[c[2500.0]]
The result is
{126.42, 0.0125525}