vec2.random() in gl-matrix

JavaScript performance comparison

Revision 5 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;
   
    // return a random float between -1 and 1
    var GLMAT_RANDOM = function() {
        return 1 - 2 * Math.random();
    };
   
    /*
    // original
    vec2.random = function (out, scale) {
        scale = scale || 1.0;
        var r = GLMAT_RANDOM() * Math.PI;
        out[0] = Math.cos(r) * scale;
        out[1] = Math.sin(r) * scale;
        return out;
    };
    */

   
    vec2.randomTest = function(out, len) {
        len = len || 1;
        var m = 0;
        while (m===0||m>1) {
            out[0] = GLMAT_RANDOM();
            out[1] = GLMAT_RANDOM();
            m = vec2.length(out);
        }
        var adjust = len / m;
        out[0] *= adjust;
        out[1] *= adjust;
        return out;
    };
   
    var out = vec2.create();
};
</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