vec2.random() in gl-matrix

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<script src="https://rawgithub.com/toji/gl-matrix/master/dist/gl-matrix-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var length = 123.456;
    var out = vec2.create();
    var GLMAT_RANDOM = Math.random;
   
    // original
    vec2.random = function (out, scale) {
        scale = scale || 1.0;
        var r = GLMAT_RANDOM() * 2.0 * Math.PI;
        out[0] = Math.cos(r) * scale;
        out[1] = Math.sin(r) * scale;
        return out;
    };
   
    // new
    vec2.randomTest = function(out, len) {
        len = len || 1;
        out[0] = .5 - GLMAT_RANDOM();
        out[1] = .5 - GLMAT_RANDOM();
        var adjust = len / vec2.length(out);
        out[0] *= adjust;
        out[1] *= adjust;
        return out;
    };
};
</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
vec2.random
vec2.random(out, length);
pending…
vec2.randomTest
vec2.randomTest(out, length);
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