How can this code be *this* slow?

I’ve been working on an infinite zoom Mandelbrot set plotter for my nephew. Even though I have a highly optimized inner loop, with only three multiplications, the code on Code dot org is extremely slow. In fact, it’s slower than it is on my 24+ year old 3.68MHz HP48GX calculator!

I’m thinking that the problem lies with Code dot org’s “interpreter within an interpreter” with regard to some of the Javascript wrapper functions. The inner loop is :

while ((rsquare + isquare) <= 4 && (temp >= 1)) {
      temp = temp - 1;
      rsquare = r*r;
      isquare = i*i;
      zrsquare = (r + i)*(r + i);
      r1 = rsquare - isquare + y;
      i = zrsquare - rsquare - isquare + x;
      r = r1;

Here is a link to the code :

Could anyone shed some light on why this code is so slow?



2 posts were merged into an existing topic: Problems with imagedata