Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Math.abs speed vs multiply full example vs steps
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/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Math.abs(x)
27924744.0 Ops/sec
compare x*x
32819730.0 Ops/sec
use steps
29904274.0 Ops/sec
Script Preparation code:
var value = -0.07 var step = 0.01 var min = -5 // sorry we must use var and not let and const 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 } function validateStepWithSteps(value, step, min = 0) { if (value == null) return false var steps = (value - min) / step var remainder = steps % 1 // Since the remainder could be close to either 0.99999999999999 or 0.00000000000001 remainder = Math.round((remainder) * 1000000000) / 1000000000 return remainder === 0 || remainder === 1 }
Tests:
Math.abs(x)
validateStepWithAbs(value, step, min)
compare x*x
validateStepWithMultiply(value, step, min)
use steps
validateStepWithSteps(value, step, min)