Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
lodash.head() vs [0]
Is head() needed only to check length !== 0 ? P.s. Empty testcase for [0] is useless because it won't crash on trying to get nonexistent element
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Not empty [0]
21.3M/s
Empty [0]
20.1M/s
Not empty lodash.head()
10.8M/s
[0] with check
10.7M/s
Empty lodash.head()
10.3M/s
[0] with null check
7.2M/s
View exact numbers
Test name
Executions per second
✓
Not empty [0]
21,275,334 Ops/sec
Empty [0]
20,057,588 Ops/sec
Not empty lodash.head()
10,791,127 Ops/sec
[0] with check
10,725,131 Ops/sec
Empty lodash.head()
10,297,880 Ops/sec
[0] with null check
7,206,290 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var a = [1,2,3]; var e = [];
Tests:
Not empty lodash.head()
_.head(a)
Not empty [0]
a[0]
Empty lodash.head()
_.head(e)
Empty [0]
e[0]
[0] with check
e.length ? e[0] : undefined
[0] with null check
e && e.length ? e[0] : undefined