A boolean argument presents an extreme challenge for #/.~ y=: 1e6 ?...@$ 2 100 timer '#/.~ y' 0.000533978 100 timer '(+/y),+/-.y' 0.00181608
In comparison: 100 timer '+/y' 0.00067356 ----- Original Message ----- From: Roger Hui <[email protected]> Date: Sunday, April 25, 2010 21:26 Subject: Re: [Jprogramming] Random Numbers with interation To: Programming forum <[email protected]> > ({.,#)/. is also supported by special code, and > ({.,#)/.~y is the same as (~.y),.#/.~y . > However, ~.y on small range integers is also > fast so the differences are hard to discern. > Which one is faster depends on the specifics > of a particular problem. > > y=: 1e6 ?...@$ 50 > a=: (~.y) ,. #/.~ y > b=: ({.,#)/.~ y > a -: b > 1 > > 100 timer '({.,#)/.~ y' > 0.00704076 > 100 timer '(~.y),.#/.~y' > 0.0127395 > > 7!:2 '#/.~y' > 1344 > > > > ----- Original Message ----- > From: Don Guinn <[email protected]> > Date: Sunday, April 25, 2010 20:32 > Subject: Re: [Jprogramming] Random Numbers with interation > To: Programming forum <[email protected]> > > > Neat. The other thing I did was use Nub to find out what the numbers > > associated with each group for Key. Is that optimized too? If > so > > then the > > code can't be improved much beyond your first suggestion. > > > > On Sun, Apr 25, 2010 at 10:19 PM, Roger Hui > <[email protected]> > > wrote: > > > > I just did it the first and easiest way I thought of. Key > is > > probably not > > > a > > > > very efficient way to count the occurrences, but it is easy. > > > > > > We endeavor to make "easy" fast. > > > > > > Key _is_ the way to count # of occurrences in J and > > > there is special code for #/. (a JKT (Joey K. Tuttle) special). > > > It is especially fast for small range integers. > > > > > > 100 timer '#/.~x' [ x=: 1e6 ?...@$ 50 > > > 0.00642733 > > > 100 timer '#/.~x' [ x=: (1e6 ?...@$ 50){50 ?...@$ 2e9 > > > 0.0305596 > > > > > > The argument in the first benchmark has small range; > > > the one in the second benchmark has large range. > > > "Large" or "small" is relative to the length of the argument. > > > > > > > > > > > > ----- Original Message ----- > > > From: Don Guinn <[email protected]> > > > Date: Sunday, April 25, 2010 17:34 > > > Subject: Re: [Jprogramming] Random Numbers with interation > > > To: Programming forum <[email protected]> > > > > > > > That is really a significant improvement. I saw only 20% > > > > improvement over > > > > the whole process where the random number generation was > > only a > > > > small part. > > > > I just did it the first and easiest way I thought of. Key is > > > > probably not a > > > > very efficient way to count the occurrences, but it is easy. > > > > > > > > On Sun, Apr 25, 2010 at 5:29 PM, Roger Hui > > <[email protected]> wrote: > > > > > > > > > There are other situations where the expression I suggested > > > > > is much more economical than the one you used. For > > example:> > > > > > > > ts=: 6!:2 , 7!:2...@] > > > > > > > > > > 10 ts '1e6 ?...@$ 2' > > > > > 0.0029846 1.04934e6 > > > > > 10 ts '?1e6 $ 2' > > > > > 0.0132888 5.24352e6 > > > > > > > > > > i.e. factor of 4 in time, factor of 5 in space. > > > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > > From: Don Guinn <[email protected]> > > > > > Date: Sunday, April 25, 2010 7:53 > > > > > Subject: Re: [Jprogramming] Random Numbers with interation > > > > > To: Programming forum <[email protected]> > > > > > > > > > > > True. There is a lot that could be done to make it > > faster. But > > > > > > it was so > > > > > > much faster I didn't bother. And as you say, if you > > can't half > > > > > > the time, > > > > > > it's not worth doing. But I did try it. Looks like > maybe 20% > > > > faster> > > > > > > > On Sun, Apr 25, 2010 at 9:18 AM, Roger Hui > > > > <[email protected]> wrote: > > > > > > > > > > > > > Slightly more economical to do 1...@#50 or 1...@$50 > > > > > > > instead of ?1e6#50 . > > > > > > > > > > > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > > > > From: Don Guinn <[email protected]> > > > > > > > Date: Sunday, April 25, 2010 5:57 > > > > > > > Subject: Re: [Jprogramming] Random Numbers with interation > > > > > > > To: Programming forum <[email protected]> > > > > > > > > > > > > > > > How about 0.07 seconds. > > > > > > > > > > > > > > > > 6!:2 '(1!:2&2)|."1]10{.\:~(>:~.z),.~ > > > > > > #/.~z=.?1e6#50'> > 15 20400 > > > > > > > > 8 20340 > > > > > > > > 46 20287 > > > > > > > > 13 20278 > > > > > > > > 33 20249 > > > > > > > > 39 20220 > > > > > > > > 18 20219 > > > > > > > > 29 20206 > > > > > > > > 25 20197 > > > > > > > > 9 20166 > > > > > > > > 0.0658392 > > > > > > > > > > > > > > > > On Sun, Apr 25, 2010 at 7:36 AM, smandula > > > > > > > > <[email protected]> wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > Thank you kindly for your reply. > > > > > > > > > The statement of one million is an example, > could be > > > > > > > > 1,000 or 50,000 > > > > > > > > > iterations. > > > > > > > > > The random numbers being tested could be 1 to > 50, > > or 1 > > > > to 100 > > > > > > > > > > > > > > > > > > I have a basic program whereby I enter the maximum > > > > iterations,> > > > in the > > > > > > > > > example 1,000,000 > > > > > > > > > and a time clock starts, and a counter starts counting > > > > up to > > > > > > > > the required > > > > > > > > > 1,000,000 intervals. > > > > > > > > > > > > > > > > > > Once, done the time duration shows, in my case 17 > > > > minutes, and > > > > > > > > a list of 10 > > > > > > > > > highest occurrences > > > > > > > > > for these random numbers. i.e. > > > > > > > > > number 29 > > occurrences 204,984 > > > > > > > > > number 26 > > occurrences 204,855 > > > > > > > > > number 40 > > occurrences 204,732 > > > > > > > > > number 17 > > occurrences 204,629 > > > > > > > > > Number 1 > > > > occurrences 204,480 > > > > > > > > > > > > > > > > > > I would appreciate any input from the forum, > > > > especially for > > > > > > > > faster times ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
