Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native Map.size vs lodash _.isEmpty
(version: 0)
measure how bad lodash performance is to check Map emptiness
Comparing performance of:
Map.size vs _.isEmpty
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js"></script>
Script Preparation code:
var m = new Map([ [1, 100], [2, 200], [3, 300], [4, 400], [5, 500] ]);
Tests:
Map.size
m.size
_.isEmpty
_.isEmpty(m)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map.size
_.isEmpty
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares the performance of two ways to check if a JavaScript `Map` is empty: **1. Using the native `size` property:** - **Description:** The `size` property of a `Map` object directly returns the number of key-value pairs it contains. A size of 0 indicates an empty map. - **Pros:** This is built into the JavaScript language, so it's efficient and concise. - **Cons:** None in this context. **2. Using the Lodash `_.isEmpty()` function:** - **Description:** Lodash is a popular JavaScript library that provides utility functions for various tasks, including checking if an object (like a `Map`) is empty. - **Pros:** Lodash often offers optimized implementations of common operations. It can also handle more complex data structures and types beyond just Maps. - **Cons:** Adding a dependency on Lodash increases the bundle size of your project. In this specific case, the native `size` property is likely to be faster. **Other Considerations:** - **Context Matters:** While `_.isEmpty()` might have performance benefits in other scenarios or with different data structures, for checking a simple Map's emptiness, the native `size` property is generally the most efficient choice. Let me know if you have any more questions!
Related benchmarks:
Array.prototype.map vs Lodash map
Array.prototype.map vs Lodash.map on large data
Lodash.js isEmpty vs Native on Map
native map vs lodash map on large array
Comments
Confirm delete:
Do you really want to delete benchmark?