Performance analysis requires a kind of triage. The first thing that sticks out about both expressions is that “0 . We need to excise that first: J is a language that expects and rewards thinking big.
(;:'Verb TimeX SpaceX') , V ,. '0.2' 8!:0 (%"1 <./) Q=:100 timespacex&> ' D' ,L:0~ V=: '+:^:(2&|)"0';']`+:@.(2&|)"0';'(* 1+2&|)' +-------------+-----+------+ |Verb |TimeX|SpaceX| +-------------+-----+------+ |+:^:(2&|)"0 |34.71| 1.00 | +-------------+-----+------+ |]`+:@.(2&|)"0| 3.70| 5.75 | +-------------+-----+------+ |(* 1+2&|) | 1.00| 2.00 | +-------------+-----+———+ Having said that, the ~35x slowdown (vs ~4x for @.) is more than a little surprising. The very specific 2x space improvement over the array solution is likely telling us something about what’s going on, but I haven’t quite thought through what it is yet. -Dan > On Dec 28, 2015, at 1:48 PM, 'Pascal Jasmin' via Programming > <[email protected]> wrote: > > timespacex '+:^:(2&|)"0 i.100000' > 0.0292787 2.10074e6 > timespacex ']`+:@.(2&|)"0 i.100000' > 0.00561727 7.08134e6 > > above code doubles odd numbers, and returns even numbers unchanged. > > > I've previously noticed that ^: seemd faster than ]`u@. ... but I guess not? > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
