Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Quaternion from axis-angle
(version: 1)
Comparing performance of:
Math.acos, cos, sin vs Math.acos, cos, sqrt vs Half-angle identity
Created:
21 days ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var N = 1000000; var xs = new Float32Array(N); var ys = new Float32Array(N); var zs = new Float32Array(N); var cos_thetas = new Float32Array(N); for (var i = 0; i < N; ++i) { const x = 2 * Math.random() - 1; const y = 2 * Math.random() - 1; const z = 2 * Math.random() - 1; const mag = Math.sqrt(x * x + y * y + z * z); xs[i] = x / mag; ys[i] = y / mag; zs[i] = z / mag; } for (var i = 0; i < N; ++i) { cos_thetas[i] = Math.cos(2 * Math.PI * Math.random()); }
Tests:
Math.acos, cos, sin
function quat_from_axis_angle(axis_x, axis_y, axis_z, cos_angle) { const angle = Math.acos(cos_angle) const cos_half_angle = Math.cos(angle / 2) const sin_half_angle = Math.sin(angle / 2) return { a: cos_half_angle, b: sin_half_angle * axis_x, c: sin_half_angle * axis_y, d: sin_half_angle * axis_z, } } for (var i = 0; i < N; ++i) { quat_from_axis_angle(xs[i], ys[i], zs[i], cos_thetas[i]); }
Math.acos, cos, sqrt
function quat_from_axis_angle(axis_x, axis_y, axis_z, cos_angle) { const angle = Math.acos(cos_angle) const cos_half_angle = Math.cos(angle / 2) const sin_half_angle = Math.sqrt(1 - cos_angle * cos_angle) return { a: cos_half_angle, b: sin_half_angle * axis_x, c: sin_half_angle * axis_y, d: sin_half_angle * axis_z, } } for (var i = 0; i < N; ++i) { quat_from_axis_angle(xs[i], ys[i], zs[i], cos_thetas[i]); }
Half-angle identity
function quat_from_axis_angle(axis_x, axis_y, axis_z, cos_angle) { const cos_half_angle = Math.sqrt((1 + cos_angle) / 2) const sin_half_angle = Math.sqrt((1 - cos_angle) / 2) return { a: cos_half_angle, b: sin_half_angle * axis_x, c: sin_half_angle * axis_y, d: sin_half_angle * axis_z, } } for (var i = 0; i < N; ++i) { quat_from_axis_angle(xs[i], ys[i], zs[i], cos_thetas[i]); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Math.acos, cos, sin
Math.acos, cos, sqrt
Half-angle identity
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
21 days ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0
Browser/OS:
Firefox 151 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Math.acos, cos, sin
24.1 Ops/sec
Math.acos, cos, sqrt
28.5 Ops/sec
Half-angle identity
64.3 Ops/sec
Related benchmarks:
soa vs aos
soa vs aos
soa vs aos
ZZZZZZ
trigata
trigata
trigata
trigata
Test sin computing
Comments
Confirm delete:
Do you really want to delete benchmark?