>Beauty only takes you so far though... i used some ts methodology to try and 
>further my understanding.

>though my forked version would seem to be faster on the Collatz function than 
>Rogers:

cg=: -:`(>:++:)`1:@.(1&=+2&|)      NB. ts = 1.09799e_5 1216
cr=: -:`(>:@(3&*))`1:@.(1&= + 2&|) NB. ts = 1.1396e_5  1152

Rogers non-forked phrase, alone, is faster than the forked version:

nf=: >:@(3&*) NB. ts = 6.20268e_6 1024
fk=: >:++:    NB. ts = 6.4832e_6  1088

>...and if you take out the additional phase length by making indirect calls 
>one sees that Rogers version is faster:

cgi=: -:`fk`1:@.(1&=+2&|) NB. ts = 1.15676e_5 1216
cri=: -:`nf`1:@.(1&=+2&|) NB. ts = 1.1123e_5  1152

>i am unsure what is going on here, i guess there is some precoding happening 
>in the indirect version which must be reevaluated in the ts if directly 
>embedded...

--- ts methodology
ts=: 1e5&(6!:2) , 7!:2@]
Because this was operating pretty near the machine noise level (~5%
level) each of these time/space stamps was done with six runs: the
first was unused as it was usually setup and the middle value of the
remaining five is shown.

Note that the stamps line up better in a Fixed Width font.

greg
~krsnadas.org

--

from: greg heil <[email protected]>
to: Programming forum <[email protected]>
date: 5 August 2014 21:59
subject: Re: [Jprogramming] Memoizing (Project Euler problem 14)

Michal

>i had a bit of a KB snafu ... actually timing results pegs cg about 20% faster 
>than collatz. The reason may well be obvious to an old time graphics 
>programmer (such as myself:) ... (>:++:) has 3 easy operations: an increment, 
>a double, and an add. Which are fast even on old 16b fixed point graphics 
>hardware! Whereas (>:@(3&*)) though it only has 2 ops has a real 
>multiplication in there (3&*). Plus i think the fork is kinda cooler:) but 
>thats just personal esthetics.

>cnv has its own memoization built right in w/o using M., results are stored 
>right in C. It is worth studying more, for me anyway.

greg
~krsnadas.org

--

from: Michal D. <[email protected]>
to: [email protected]
date: 5 August 2014 19:01
subject: Re: [Jprogramming] Memoizing (Project Euler problem 14)

Oops, sorry for the premature post.

---

>Thanks for the prod Greg, I understand *`* now, at least somewhat :-)

>I think I would prefer the below which avoids factoring the multiplication as 
>(x+1)+(2*x), although that's a pretty cute trick.  *1+3*]* has the advantage 
>of having only two operations (one +, one *) instead of three (two +, one *).

*cgv=:  13 : '(2|y)}  (<.-:)`(1+3*])`:0 y'*

>Roger's version wins by a long shot (2.2 vs 2.1 vs 1.7).  It invokes fewer 
>verbs.  The interesting thing is that it's collatzv that runs faster not the 
>code that follows - meaning that the interpreter is smart enough to use 
>integer arithmetic before we even get to *<.* ?!?

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

Reply via email to