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
Test name
Executions per second
If Statement - True
3308259.8 Ops/sec
If Statement - False
12299265.0 Ops/sec
Calculate - Positive
4087919.8 Ops/sec
Calculate - Zero
4026230.8 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)