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 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0
Browser:
Firefox 130
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
If Statement - True
230921392.0 Ops/sec
If Statement - False
546042496.0 Ops/sec
Calculate - Positive
262291968.0 Ops/sec
Calculate - Zero
239104240.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)