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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser:
Chrome 127
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Empty [0]
20.6M/s
Not empty [0]
20.5M/s
[0] with check
8.5M/s
Not empty lodash.head()
8.4M/s
Empty lodash.head()
8.2M/s
[0] with null check
6.2M/s
View exact numbers
Test name
Executions per second
✓
Empty [0]
20,569,704 Ops/sec
Not empty [0]
20,548,156 Ops/sec
[0] with check
8,483,849 Ops/sec
Not empty lodash.head()
8,401,816 Ops/sec
Empty lodash.head()
8,248,821 Ops/sec
[0] with null check
6,211,580 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