Random 4x1 Vector Calculator (v2)

Revision 2 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


Test runner

Ready to run.

Testing in
TestOps/sec
v3.4.1
var scale = 1.0;
var out = [];

var v1, v2, v3, v4;
var s1, s2;
do {
	v1 = Math.random() * 2 - 1;
	v2 = Math.random() * 2 - 1;
	s1 = v1 * v1 + v2 * v2;
} while (s1 >= 1);
do {
	v3 = Math.random() * 2 - 1;
	v4 = Math.random() * 2 - 1;
	s2 = v3 * v3 + v4 * v4;
} while (s2 >= 1);

var d = Math.sqrt((1 - s1) / s2);
out[0] = scale * v1;
out[1] = scale * v2;
out[2] = scale * v3 * d;
out[3] = scale * v4 * d;
ready
toji/gl-matrix#458
var scale = 1.0;
var out = [];

var v1, v2, v3, v4;
var s1, s2;
var rand;
  
rand = Math.random();
v1 = rand * 2 - 1;
v2 = (4 * Math.random() - 2) * Math.sqrt(rand * -rand + rand);
s1 = v1 * v1 + v2 * v2;

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

var d = Math.sqrt((1 - s1) / s2);
out[0] = scale * v1;
out[1] = scale * v2;
out[2] = scale * v3 * d;
out[3] = scale * v4 * d;
ready

Revisions

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