Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
optional chaining vs. non-optional chaining
Determine performance cost of using optional chaining when not required
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/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
Without optional chaining
23.8M/s
optional chaining (?.) once
23.5M/s
optional chaining (?.) two levels
23.5M/s
View exact numbers
Test name
Executions per second
✓
Without optional chaining
23,771,608 Ops/sec
optional chaining (?.) once
23,529,680 Ops/sec
optional chaining (?.) two levels
23,476,628 Ops/sec
Script Preparation code:
var job = { "summary": { "total_actions": 4, "finished_actions": 4 }, "updated_at": "2020-07-15T10:24:42.364000000Z", "job_id": "4b1733e7-c8e0-4fdd-a7f1-13d3ab725c92", "description": "Job from our export", "created_at": "2020-07-15T10:24:40.975000000Z", "status": "finished", "tags": { "export_id": [ "8848c5d8-fd44-43c0-b7f2-1428d0f4891a" ] } }
Tests:
Without optional chaining
if (job.tags.export_id) { // do nothing }
optional chaining (?.) once
if (job.tags?.export_id) { // do nothing }
optional chaining (?.) two levels
if (job?.tags?.export_id) { // do nothing }