Three.js closure vs. pre-allocated

JavaScript performance comparison

Revision 2 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.sub( c, b ).crossSelf(
                     THREE.Plane.__v2.sub( 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.sub( c, b ).crossSelf( v2.sub( 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…

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