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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
If Statement - False
12.3M/s
Calculate - Positive
4.1M/s
Calculate - Zero
4.0M/s
If Statement - True
3.3M/s
View exact numbers
Test name
Executions per second
✓
If Statement - False
12,299,265 Ops/sec
Calculate - Positive
4,087,920 Ops/sec
Calculate - Zero
4,026,231 Ops/sec
If Statement - True
3,308,260 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)