vec4.random() in gl-matrix

JavaScript performance comparison

Revision 2 of this test case created and last updated

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 = vec4.create();
    var GLMAT_RANDOM = Math.random;
   
    // original
    vec4.random = function (out, scale) {
        scale = scale || 1.0;
   
        //TODO: This is a pretty awful way of doing this. Find something better.
        out[0] = GLMAT_RANDOM();
        out[1] = GLMAT_RANDOM();
        out[2] = GLMAT_RANDOM();
        out[3] = GLMAT_RANDOM();
        vec4.normalize(out, out);
        vec4.scale(out, out, scale);
        return out;
    };
   
    // new
    vec4.randomTest = function(out, len) {
        len = len || 1;
        out[0] = .5 - GLMAT_RANDOM();
        out[1] = .5 - GLMAT_RANDOM();
        out[2] = .5 - GLMAT_RANDOM();
        out[3] = .5 - GLMAT_RANDOM();
        var adjust = len / vec4.length(out);
        out[0] *= adjust;
        out[1] *= adjust;
        out[2] *= adjust;
        out[3] *= 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
vec4.random
vec4.random(out, length);
pending…
vec4.randomTest
vec4.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