Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.isFinite vs Object.isFinite
(version: 1)
Measuring approaches performance
Comparing performance of:
Lodash isFinite vs Native isFinite
Created:
one year ago
by:
Guest
Go to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.js"></script>
Script Preparation code:
var value = 123456;
Tests:
Lodash isFinite
_.isFinite(value);
Native isFinite
Number.isFinite(value);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash isFinite
Native isFinite
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Native isFinite
176.9M/s
Lodash isFinite
162.0M/s
View exact numbers
Test name
Executions per second
✓
Native isFinite
176,937,552 Ops/sec
Lodash isFinite
162,021,568 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark defined here compares the performance of two functions that determine whether a value is a finite number: `_.isFinite` from the Lodash library and `Number.isFinite`, the native method provided by JavaScript. ### Comparison of Options: 1. **Lodash's `_.isFinite(value)`** - **Library Description**: Lodash is a JavaScript utility library that provides functions for common programming tasks, including manipulating arrays, numbers, objects, strings, etc. The `_.isFinite` function checks if the value is a finite number. It first converts the value to a number and then checks if the result is finite. - **Pros**: - Uniform API across various Lodash functions, making it a consistent choice for developers already leveraging Lodash. - Handles edge cases gracefully by converting values to numbers. - **Cons**: - Introduces an external dependency, which adds to the overall bundle size of the application, potentially impacting performance. - May be slower than native methods because it involves type coercion and additional processing overhead that can be avoided using the native implementation. 2. **Native `Number.isFinite(value)`** - **Library Description**: Introduced in ECMAScript 2015 (ES6), `Number.isFinite` checks whether a given value is a finite number without converting the value to a number type. This means it returns false for non-numeric values and positive/negative infinity. - **Pros**: - Performance advantage, as shown in the benchmarking results, which demonstrate higher execution speed with more executions per second. - No additional dependencies, which keeps the application lightweight and reduces bundle size. - **Cons**: - It does not handle non-numeric inputs gracefully; values like `'123'` or `true` will return false without type coercion. ### Benchmark Results: From the benchmark results, we see that `Number.isFinite` performed significantly better, achieving around **176 million executions per second**, compared to Lodash's `_.isFinite`, which resulted in about **162 million executions per second**. This indicates that for high-performance scenarios, especially in tight loops or repeated function calls, the native method should be preferred. ### Other Considerations: Choosing between these two approaches depends on the specific needs of the project: - If your application already uses Lodash extensively, you might prefer using `_.isFinite` for consistency across your codebase. - If performance is a critical factor, especially in performance-sensitive applications, opting for the native `Number.isFinite` is advisable due to its efficiency and reduced overhead. ### Alternatives: There are a few alternative approaches, such as: - Using a simple combination of `isNaN` and type checking (e.g., `typeof value === 'number' && !isNaN(value)`), although this approach may result in more verbose code. - Custom implementations that may combine characteristics of both libraries without introducing external dependencies. In summary, while Lodash offers some useful utilities, the native `Number.isFinite` method is typically a more efficient choice for checking if a value is finite, especially when performance is a concern.
Related benchmarks
lodash.isFinite vs native isFinite
lodash.isFinite vs Number.isFinite
Lodash isEmpty vs Object.keys().length not empty 123
Lodash some vs JavaScript Object.values and some
Comments
Confirm delete:
Do you really want to delete benchmark?