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:
2 years ago
If Statement - False
450.6M/s
Calculate - Positive
143.6M/s
Calculate - Zero
131.9M/s
If Statement - True
131.0M/s
View exact numbers
Test name
Executions per second
✓
If Statement - False
450,608,416 Ops/sec
Calculate - Positive
143,557,504 Ops/sec
Calculate - Zero
131,886,624 Ops/sec
If Statement - True
131,041,256 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)