Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
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; rv:122.0) Gecko/20100101 Firefox/122.0
Browser:
Firefox 122
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Math.sqrt
155349072.0 Ops/sec
all squared
331338400.0 Ops/sec
all squared 1
335057536.0 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;