Three.js closure vs. pre-allocated

JavaScript performance comparison

Revision 5 of this test case created

Preparation code

``<script src="https://raw.github.com/mrdoob/three.js/master/build/three.min.js"></script><script>  Benchmark.prototype.setup = function() {    var A = new THREE.Vector3();    var B = new THREE.Vector3();    var C = new THREE.Vector3();        function setFromCoplanarPoints1( a, b, c ) {        var normal = THREE.Plane.__v1.subVectors( c, b ).cross(                     THREE.Plane.__v2.subVectors( a, b ) ).normalize();        return normal;    }        var setFromCoplanarPoints2 = (function() {        var v1 = new THREE.Vector3();        var v2 = new THREE.Vector3();        return function ( a, b, c ) {            var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();            return normal;        };    })();        var random = [];    for( var i = 0; i < 10000; i ++ ) {       random.push( Math.random() );    }        var nextRandom = 0;  };</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
Pre-allocated
``var i = nextRandom;A.set(random[i++], random[i++], random[i++]);B.set(random[i++], random[i++], random[i++]);C.set(random[i++], random[i++], random[i++]);var tmp = setFromCoplanarPoints1(A, B, C);nextRandom = i % ( random.length - 100 );``
pending…
Closure
``var i = nextRandom;A.set(random[i++], random[i++], random[i++]);B.set(random[i++], random[i++], random[i++]);C.set(random[i++], random[i++], random[i++]);var tmp = setFromCoplanarPoints2(A, B, C);nextRandom = i % ( random.length - 100 );``
pending…

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: