Math object speed in javascript

I am working on a javascript application that makes heavy use of math operations, dozens of mouse click calls. I worked on other people's code as a starting point, and I often find work around my own javascript math, for example ...

var pi = Math.PI
var distance = (x * x) + (y * y) / R * R
var pixels = ~~(x/y)

Is there significant success for using the Math object? If so, what are some common workarounds?

+5
source share
2 answers

If for some reason you are engaged in computational intensity in javascript, you should remember these things (* and read David Mandelin Know your engines: how to make your JavaScript Quick presentation - PDF , where he describes it in more detail *):

  • , .

  • , .

, distance(), Math.method() .

sqrt, , , x*x, random , Pi , , min max .


PS: - ((x >= 0 ? x : -x) + 0.5) >> 0, Math.ceil(Math.abs()), - "" - , , , . JavaScript RIA - , . ,

+15

. if , .

0

All Articles