Closure Compiler vs Hand Optimized Vectors

JavaScript performance comparison

Test case created by Click for Info

Preparation code

<script>
  function add(v1, v2) {
   return {
    x: v1.x + v2.x,
    y: v1.y + v2.y
   }
  }
 
  function lengthSq(vec) {
   return vec.x * vec.x + vec.y * vec.y;
  }
 
  function testbase(v11, v12, v21, v22) {
   return lengthSq(add({
    x: v11,
    y: v12
   }, {
    x: v21,
    y: v22
   }))
  }
 
  function testggcc(b, c, a, d) {
   b = {
    x: b,
    y: c
   };
   a = {
    x: a,
    y: d
   };
   a = {
    x: b.x + a.x,
    y: b.y + a.y
   };
   return a.x * a.x + a.y * a.y
  };
 
  function testhand(a, b, c, d) {
   return (a + c) * (a + c) + (b + d) * (b + d)
  };
 
  var v;
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Original Code
testbase(1.2, 3.4, 5.6, 7.8);
pending…
Google Closure Compiler
testggcc(1.2, 3.4, 5.6, 7.8);
pending…
Hand optimized
testhand(1.2, 3.4, 5.6, 7.8);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment