0

I am experimenting some graphics functions which I learned at the class. In the book, it says that integer calculation improves performance in C++. But I am doing it on JavaScript. Does it matter in Javascript?

On Chrome, it runs smoothly. Not surprisingly, its performance decreases significantly in Firefox 19 and IE10

function circ(cx, cy, rad, color){  //Using second-order differential
            var x = 0;
            var y = rad;
            var d = 1 - rad;
            var deltaE = 3;
            var deltaSE = -2*rad+5;
            ctx.beginPath();
            ctx.strokeStyle = color;
            ptc(cx,cy,x,y);
            while(y>x){
                if(d<0){                //Select E
                    d+=deltaE;
                    deltaE +=2;
                    deltaSE +=2;
                }
                else{                   //Select SE
                    d+=deltaSE;
                    deltaE+=2;
                    deltaSE+=4;
                    y--;
                }
                x++;
                ptc(cx,cy,x,y);
            }
            ctx.stroke();

        }

1 Answer 1

1

If you are dealing with very large fractions then sure, the simpler the numbers the faster it'll run, but the less smooth any animation based on that number will be.

Sign up to request clarification or add additional context in comments.

3 Comments

my calculation is based on mouse movement. then integer coordinates of mouse are used only for addition. I guess there is no real value in calculation.
Yeah if you are doing x, y coordinates from mouse movement don't worry about using another other than an integer value.
thanks. I was just experimenting this thing. Apparently, the performance of html5 canvas.arc is way better than above function. it is fun, though :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.