First, please have a look at this site:

http://www.timestretch.com/FractalBenchmark.html

I ran the python code on my machine with Python 2.5 and got the result
of 4.36 secs(compared to 15.33 secs shown on the page). Adding import
psyco;psyco.full() at the top of the code, which does run-time code
optimization, increased speed: 0.98 secs. Cool. Now I thought J could
do better, or at least do as well, since this kind of problem is what
J's good at.

Now I translated the code into J. First version, which was more or
less sentence to sentence translated, ran for more than a minute. I
optimised incrementally, from vectorizing x value and then to
vectorizing both x and y. Now I get 9.87 secs with the following code:

BAILOUT=. 16
MAX_ITERATIONS=. 1000

run=: 3 : 0
   smoutput 'Rendering...'
   i=. mb~ 40%~ _39+i.78
   (i<:BAILOUT){' *'
)

mb=: 4 : 0
   cr=. y-0.5
   ci=. x
   zi=. (y,&#x)$0
   zr=. (y,&#x)$0
   for. i. MAX_ITERATIONS do.
       temp=. zr*zi
       zr2=. *:zr
       zi2=. *:zi
       zr=. (cr+zr2)-zi2
       zi=. (+:temp)+"1 ci
   end.
   zi2+zr2
)

Now compare this to the running time of Vectorized Io, which is 0.41
secs according to the benchmark on the web page.

I could use complex numbers, which is more natural for this problem.
What else can I do to speed it up significantly?

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

Reply via email to