How can I reduce the number of function calls in my code?
Why not evaluate e1
and g
only once in your function definitions:
e1[x1_, x2_, x3_] := Cross[{x1, x3, x2}, {1, x2, x1}]
f1[x1_, x2_, x3_] := With[{e = e1[x1, x2, x3]}, e[[2]]/e[[3]]]
g1[x1_, x2_, x3_] := With[{f = f1[x1, x2, x3]}, {0, f, f^2}]
h1[(x1_)?NumericQ, (x2_)?NumericQ] := NIntegrate[g1[x1, x2, x3][[2]], {x3, 0, 1}];
Then:
CurrentValue[EvaluationNotebook[],"DebuggerSettingsDebuggerEnabled"] =True;
RuntimeTools`Profile[Plot[h1[t^2,t],{t,1,2*Pi}]];
produces the profile:
You can reduce the number of function calls by using PlotPoints
:
RuntimeTools`Profile[Plot[h1[t^2, t], {t, 1, 2*Pi}, PlotPoints -> 10]]