Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
normalize vector - Math.sqrt vs all squared vs all squared 1
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
all squared
130.8M/s
all squared 1
123.0M/s
Math.sqrt
10.6M/s
View exact numbers
Test name
Executions per second
✓
all squared
130,789,576 Ops/sec
all squared 1
123,038,856 Ops/sec
Math.sqrt
10,640,907 Ops/sec
Tests:
Math.sqrt
const x = 1; const y = -1; const velocity = { x: 0, y: 0 }; const length = Math.sqrt(x * x + y * y); velocity.x = length > 0 ? x / length : 0; velocity.y = length > 0 ? y / length : 0;
all squared
const x = 1; const y = -1; const velocity = { x: 0, y: 0 }; const lengthSquared = x ** 2 + y ** 2; velocity.x = (lengthSquared > 0 ? x ** 2 / lengthSquared : 0) * (x < 0 ? -1 : 1); velocity.y = (lengthSquared > 0 ? y ** 2 / lengthSquared : 0) * (y < 0 ? -1 : 1);
all squared 1
const x = 1; const y = -1; const velocity = { x: 0, y: 0 }; const lengthSquared = x ** 2 + y ** 2; const velocityScale = lengthSquared > 0 ? 1 / lengthSquared : 0; velocity.x = x * velocityScale; velocity.y = y * velocityScale;