Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Math.abs speed vs multiply full example
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/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Math.abs(x)
618421.1 Ops/sec
compare x*x
2589653.2 Ops/sec
Script Preparation code:
var value = -0.07 var step = 0.01 var min = -5 function validateStepWithAbs(value, step, min = 0) { if (value == null) return false var absValue = Math.abs(value) var absStep = Math.abs(step) var absMin = Math.abs(min) while ( (absValue > 0 && absValue < 1) || (absStep > 0 && absStep < 1) || (absMin > 0 && absMin < 1) ) { value *= 10 step *= 10 min *= 10 absValue = Math.abs(value) absStep = Math.abs(step) absMin = Math.abs(min) } return (value - min) % step === 0 } function validateStepWithMultiply(value, step, min = 0) { if (value == null) return false while ( (value !== 0 && value * value < 1) || (step !== 0 && step * step < 1) || (min !== 0 && min * min < 1) ) { value *= 10 step *= 10 min *= 10 } return (value - min) % step === 0 }
Tests:
Math.abs(x)
validateStepWithAbs(value, step, min)
compare x*x
validateStepWithMultiply(value, step, min)