(x f/@:g y) for atomic f and g has had special code for a long time.
The special code calculates (x g y) on each cell of g, and applies (f/)
on each cell as it is created. Thus (x g y) is never created in full.
I revisited this for 9.03 beta-d. I found that the special code was
slower than the simple version in some cases:
* less than 4 atoms per item of g
* less then 4 items of g
* g can be executed inplace
and I turned the special code off in those cases. Now I get
50 timespacex '+/ 8 % tstdata'
0.005984 4.19581e6
50 timespacex '8 +/@:% tstdata'
0.00598417 4.19594e6
But I can offer you one improvement:
50 timespacex '8. +/@:% tstdata'
0.0034118 4.196e6
Henry Rich
On 3/13/2021 7:10 PM, Ric Sherlock wrote:
I was initially surprised by the big differences in performance between
different formulations of the sum of the quotients
tstdata=: _2 */\ 1+2*i.1000000
50 timespacex '+/ 8 % tstdata'
0.00206915 4.19581e6
50 timespacex '8 +/@:% tstdata'
0.0686648 1792
The first is up to 113 times faster (depending on platform and J version),
the 2nd is over 2000 times leaner. I see similar differences back to J602.
I think this surprised me because I am usually comparing the sum of
products. In that case I guess the special code for +/@:* hides the "usual"
difference
50 timespacex '+/ 8 * tstdata'
0.00193723 4.19581e6
50 timespacex '8 +/@:* tstdata'
0.00042151 1664
It does make we wonder if we can't do better for quotient? I imagine the
answer is yes but whether it is worth it depends on how often it is used.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
This email has been checked for viruses by AVG.
https://www.avg.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm