(+/ % #)\ Improved |
initial writing: 2003-11-10 last updated: 2003-12-04 |
The dyad (+/ % #)\ computes the moving average and is now implemented by special code for positive left arguments and integer and floating point right arguments. The following table illustrates the improvements in time and space.
x=: 0.01*?n$1000 ts=: 6!:2 , 7!:2@] NB. time and space ts 'm (+/ % #)\x'
m | n | J 5.03 | J 5.02 | Ratio | ||||||||
50 | 1e5 | 0.010857 | 1.051264e6 | 0.428732 | 3.148352e6 | 39.49 | 2.99 | |||||
50 | 2e5 | 0.021686 | 2.099840e6 | 0.855940 | 6.294080e6 | 39.47 | 3.00 | |||||
50 | 4e5 | 0.047796 | 4.196992e6 | 1.693698 | 1.258554e7 | 35.44 | 3.00 | |||||
50 | 8e5 | 0.097144 | 8.391296e6 | 3.408151 | 2.516845e7 | 35.08 | 3.00 | |||||
100 | 1e5 | 0.011251 | 1.051264e6 | 0.467502 | 3.148864e6 | 41.55 | 3.00 | |||||
100 | 2e5 | 0.022939 | 2.099840e6 | 0.920847 | 6.294592e6 | 40.14 | 3.00 | |||||
100 | 4e5 | 0.044595 | 4.196992e6 | 1.843981 | 1.258605e7 | 41.35 | 3.00 | |||||
100 | 8e5 | 0.092017 | 8.391296e6 | 3.680761 | 2.516896e7 | 40.00 | 3.00 | |||||
200 | 1e5 | 0.011448 | 1.051264e6 | 0.625874 | 3.149888e6 | 54.67 | 3.00 | |||||
200 | 2e5 | 0.022340 | 2.099840e6 | 1.255497 | 6.295616e6 | 56.20 | 3.00 | |||||
200 | 4e5 | 0.045064 | 4.196992e6 | 2.504865 | 1.258707e7 | 55.58 | 3.00 | |||||
200 | 8e5 | 0.089157 | 8.391296e6 | 5.023058 | 2.516998e7 | 56.34 | 3.00 | |||||
400 | 1e5 | 0.011027 | 1.051264e6 | 0.776791 | 3.151936e6 | 70.45 | 3.00 | |||||
400 | 2e5 | 0.022462 | 2.099840e6 | 1.565228 | 6.297664e6 | 69.68 | 3.00 | |||||
400 | 4e5 | 0.047861 | 4.196992e6 | 3.124304 | 1.258912e7 | 65.28 | 3.00 | |||||
400 | 8e5 | 0.091099 | 8.391296e6 | 6.275170 | 2.517203e7 | 68.88 | 3.00 |