Search code examples
javascriptnode.jsperformancetyped-arrays

Storing coords in javascript as a 2D Vector Class


Which one would be better? (for memory and calculation speed)

  1. new Float32Array(2);
  2. new Float64Array(2);
  3. {x: 0, y: 0};
  4. [0, 0];

Obviously 1. is more memory efficient than 2, but what about speed? 32 bits calculations will be faster than 64 bits? What about the others?


Solution

  • Take a look at this answer. Float32Arrays are used for WebGL apps.
    Also, arrays are always faster than objects, for example that's why Elm use arrays to construct it's virtual DOM.