[Jprogramming] Speed of prefix and suffix
Alex Shroyer
ashroyer at gmail.com
Tue Feb 2 14:17:48 UTC 2016
Good to know! I didn't appreciate this before.
On Mon, Feb 1, 2016 at 7:38 AM, Henry Rich <henryhrich at gmail.com> wrote:
> See
>
> http://code.jsoftware.com/wiki/Vocabulary/bslash#More_Information
>
> Henry Rich
>
>
> On 2/1/2016 5:51 AM, Ben Gorte - CITG wrote:
>
>> Good morning,
>>
>> I stumbled into something I found funny, but perhaps is widely known:
>> Sometimes, u/\. is much much faster than u/\ . In my application it makes
>> the difference between 'perfect' and 'useless'. For example:
>>
>> timespacex 'plus /\ i.1000'
>> 0.209933 44928
>> timespacex 'plus /\. i.1000'
>> 0.000542 19840
>>
>> Apparently J realizes that u/\. can be done incrementally (going from
>> back to front) for any u, whereas the u/ part of u/\ is done from the
>> beginning over and over. With a vplus that says what it is doing you see:
>>
>> vplus/ \ i.5
>> 0+1
>> 1+2
>> 0+3
>> 2+3
>> 1+5
>> 0+6
>> 3+4
>> 2+7
>> 1+9
>> 0+10
>> 0 1 3 6 10
>> vplus/ \. i.5
>> 3+4
>> 2+7
>> 1+9
>> 0+10
>> 10 10 9 7 4
>>
>> Indeed, appendix B of the dictionary contains the line
>> u/\. monad special code
>> whereas there is no such line for u/\ .
>>
>> In addition there is special code for many u/\ with built-in u. For user
>> defined (associative, commutative?) u you can use u/\. &. |. instead of u/\
>> and it will be much faster.
>>
>> timespacex 'plus /\.&.|. i.1000'
>> 0.000571 28928
>>
>> vplus /\. &.|.i.5
>> 1+0
>> 2+1
>> 3+3
>> 4+6
>> 0 1 3 6 10
>>
>> Ben
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list