public
Last active

  • Download Gist
Timings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
In[1]:= n = 400;
 
In[2]:= TimeAv[Plus@@ReplaceList[Product[y[j], {j, 1, n}], y[i_] rest_ :> x[i] rest];]
 
During evaluation of In[2]:= Total wall time is 0.554032,
total cpu time is 0.530403 and total time spent evaluating the expression is 0.53040
 
During evaluation of In[2]:= The expression was evaluated 6 times, without any blocking of the runs.
This yields a mean timing of 0.088401 with a standard deviation of 0.0074.
 
Out[2]= {0.088401, Null}
 
In[3]:= TimeAv[Sum[x[i] Product[y[j], {j, Delete[Range[n], i]}], {i, 1, n}];]
 
During evaluation of In[3]:= Total wall time is 0.652037, total cpu time is 0.639604
and total time spent evaluating the expression is 0.60840
 
During evaluation of In[3]:= The expression was evaluated 2 times, without any blocking of the runs.
This yields a mean timing of 0.304202 with a standard deviation of 0.14820.
 
Out[3]= {0.304202, Null}
 
In[4]:= TimeAv[Tr[Times@@@SparseArray[{{i_, i_} -> x@i, {i_, j_} -> y@j}, {n, n}]];]
 
During evaluation of In[4]:= Total wall time is 4.654266, total cpu time is 4.508429
and total time spent evaluating the expression is 4.44603
 
During evaluation of In[4]:= The expression was evaluated 10 times, without any blocking of the runs.
This yields a mean timing of 0.444603 with a standard deviation of 0.0290.
 
Out[4]= {0.444603, Null}
 
In[5]:= TimeAv[f = Array[x, n]; g = Array[y, n];
Total[f[[#]] (Times @@ g)/g[[#]] & /@ Range[n]];]
 
During evaluation of In[5]:= Total wall time is 0.565032, total cpu time is 0.577204
and total time spent evaluating the expression is 0.57720
 
During evaluation of In[5]:= The expression was evaluated 3 times, without any blocking of the runs.
This yields a mean timing of 0.192401 with a standard deviation of 0.0074.
 
Out[5]= {0.192401, Null}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.