Wolfram Language Speed Guide

By Xah Lee. Date: .

Apply Plus vs Total vs Norm

Equivalent way to define a function. This computes geometric inversion.

Clear[testData, f1,f2,f3,f4,result1 , result2 , result3 , result4 ];

testData = Table[RandomReal[],{2* 10^6 },{3}];

f1[p_] := p/(Plus @@ (p^2));
f2 = #/(Plus@@(#^2))&;
f3 = #/Norm[#]^2 &;
f4 = #/Total[#^2] &;

Timing[result1=f1/@testData]//First
Timing[result2=f2/@testData]//First
Timing[result3=f3/@testData]//First
Timing[result4=f4/@testData]//First

result1 == result2 == result3 == result4
Apply Plus vs Total vs Norm 2021-08-02
Apply Plus vs Total vs Norm 2021-08-02

Conclusion:

WolframLang Table vs Array

Clear[n, result1, result2, result3 ];
n=100;

result1= Timing@ Table[Cube[{x,y,z},1],{x,-n,n},{y,-n,n},{z,-n,n}];
result2= Timing@ Array[Cube[{##},1]&,{2 n+1,2 n+1,2 n+1},{-n,-n,-n}];
result3= Timing@ Array[Cube[{#1,#2,#3},1]&,{2 n+1,2 n+1,2 n+1},{-n,-n,-n}];

result1[[1]]
result2[[1]]
result3[[1]]

result1[[2]] == result2[[2]] == result3[[2]]
WolframLang Table vs Array 2021-08-02
WolframLang Table vs Array 2021-08-02

Conclusion:

WolframLang Guide