Random 4x1 Vector Calculator (v3)

Revision 3 of this benchmark created on


Description

A performance comparison between the vec4.random function in glMatrix v3.4.1 and the equivalent function proposed in toji/gl-matrix#458.

Setup

const glMatrix = { "RANDOM": Math.random };

Test runner

Ready to run.

Testing in
TestOps/sec
v3.4.1
var v1, v2, v3, v4;
var s1, s2;
do {
	v1 = glMatrix.RANDOM() * 2 - 1;
	v2 = glMatrix.RANDOM() * 2 - 1;
	s1 = v1 * v1 + v2 * v2;
} while (s1 >= 1);
do {
	v3 = glMatrix.RANDOM() * 2 - 1;
	v4 = glMatrix.RANDOM() * 2 - 1;
	s2 = v3 * v3 + v4 * v4;
} while (s2 >= 1);
ready
toji/gl-matrix#458
var v1, v2, v3, v4;
var s1, s2;
var rand;

rand = glMatrix.RANDOM();
v1 = rand * 2 - 1;
v2 = (4 * glMatrix.RANDOM() - 2) * Math.sqrt(rand * -rand + rand);
s1 = v1 * v1 + v2 * v2;

rand = glMatrix.RANDOM();
v3 = rand * 2 - 1;
v4 = (4 * glMatrix.RANDOM() - 2) * Math.sqrt(rand * -rand + rand);
s2 = v3 * v3 + v4 * v4;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.