FWIW, pending J6.02, this offers some improvement in
time and space:
NB. in J 6.0.1
NB. reduce x to an integer multiple of y before divide
NB. does it work for -ve & +ve x
(x-300000) (<[EMAIL PROTECTED] -: ([ - |~) % ]) 17
1
ts'x <[EMAIL PROTECTED] 17'
0.210536 2.09723e7
ts'x (([ - |~) % ]) 17'
0.0587469 1.25841e7
I expect there's a better way still, and still in 6.01 !
Mike
Roger Hui wrote:
Preliminary benchmarks:
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
x=: 1e6 [EMAIL PROTECTED] 2e6
ts 'Expression'
Expression J6.02x J6.01 Factor
x <[EMAIL PROTECTED] 512 0.0054822 4.19507e6 0.136416 2.09723e7 23.80 5.00
x <[EMAIL PROTECTED] 17 0.0213073 4.19507e6 0.154837 2.09723e7 7.27 5.00
----- Original Message -----
From: Roger Hui <[EMAIL PROTECTED]>
Date: Friday, October 20, 2006 8:24 am
Subject: Re: [Jprogramming] Interger division, the faster one
That is a good idea. The improvement should be
around a factor of 10 in time and a factor of 2
in space.
----- Original Message -----
From: Oleg Kobchenko <[EMAIL PROTECTED]>
Date: Friday, October 20, 2006 1:03 am
Subject: [Jprogramming] Interger division, the faster one
I expected there'd be special code for (<[EMAIL PROTECTED]). Alas,
6!:2 '(i.1e6) % 256'
0.0246238
6!:2 '(i.1e6) <[EMAIL PROTECTED] 256'
0.208256
6!:2 '(i.1e6) <.@:% 256'
0.236405
For powers of 2 there's still
6!:2 '_8 (33 b.) (i.1e6)'
0.0162501
((i.1e6) <[EMAIL PROTECTED] 256) -: _8 (33 b.) (i.1e6)
1
Viewmat improvement
~~~~~~~~~~~~~~~~~~~
Thus this change makes complex viewmat ~x3.5 faster.
k=. <.256*x - <. x NB. both times
...
mat=. _8(33 b.) (t *"2 k) + b (*"2) 256-k
...
mat=. _8(33 b.) (t * k) + b * 256-k
...
mat=. 256 #. mat
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm