The performance hit from each and every arise specifically because they 
introduce an (implicit) “0 . In fact, in this context, every is identical to 
straight “0 .  Each uses more space because the results are boxed instead of 
numeric. Boxes have like a 24 byte overhead for each box (something like that), 
and here you’re boxing every single atom.

-Dan

> On Jan 4, 2016, at 6:20 PM, 'Pascal Jasmin' via Programming 
> <[email protected]> wrote:
> 
> performance is about the same when each is used instead, and not so different 
> from "0
> 
> 
> timespacex ']`+:@.(2&|) each i.1000'
> 0.000423999 509056
>    timespacex '+:^:(2&|) each i.1000'
> 0.000448319 300416
>    timespacex '+:^:(2&|)"0 i.1000'
> 0.000360319 19968
> 
>  timespacex '+:^:(2&|) every i.1000'
> 0.000480319 20224
>  timespacex ']`+:@.(2&|) every i.1000'
> 0.000423359 20736
> 
> 
> there is a large space difference with each but not with every.
> 
> 
> ----- Original Message -----
> From: Dan Bron <[email protected]>
> To: J Programming <[email protected]>
> Sent: Monday, January 4, 2016 12:13 PM
> Subject: Re: [Jprogramming] a performance quirk
> 
> 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
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to