Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
If statements vs zero multiplication and assignment
Is it faster to check if a numeric calculation needs to be performed and assigned to an object property, or just do the calculation against zero and assign it anyway.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0
Browser:
Firefox 127
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
If Statement - True
131041256.0 Ops/sec
If Statement - False
450608416.0 Ops/sec
Calculate - Positive
143557504.0 Ops/sec
Calculate - Zero
131886624.0 Ops/sec
Script Preparation code:
var DO_MATHS_TRUE = true, DO_MATHS_FALSE = false, DELTA = 12345, OBJ_SRC = {x: 12}, OBJ_SRC_ZERO = {x: 0}, OBJ_DEST = {x: 0};
Tests:
If Statement - True
if(DO_MATHS_TRUE){ OBJ_DEST.x += (OBJ_SRC.x * DELTA) }
If Statement - False
if(DO_MATHS_FALSE){ OBJ_DEST.x += (OBJ_SRC.x * DELTA) }
Calculate - Positive
OBJ_DEST.x += (OBJ_SRC.x * DELTA)
Calculate - Zero
OBJ_DEST.x += (OBJ_SRC_ZERO.x * DELTA)