Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Get Fs
(version: 0)
Comparing performance of:
Hybrid vs Lodash vs Native JS
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var fs = { f1: { A: ["id1", "id2"], B: ["id1", "id2"], C: ["id1", "id2"], D: ["id1", "id2"], E: ["id1", "id2"], F: ["id1", "id2"], }, f2: { A: ["id1", "id2"], B: ["id1", "id2"], C: ["id1", "id2"], D: ["id1", "id2"], E: ["id1", "id2"], F: ["id1", "id2"], }, f3: { A: ["id1", "id2"], B: ["id1", "id2"], C: ["id1", "id2"], D: ["id1", "id2"], E: ["id1", "id2"], F: ["id1", "id2"], }, f4: { A: ["id1", "id2"], B: ["id1", "id2"], C: ["id1", "id2"], D: ["id1", "id2"], E: ["id1", "id2"], F: ["id1", "id2"], }, f5: { A: ["id1", "id2"], B: ["id1", "id2"], C: ["id1", "id2"], D: ["id1", "id2"], E: ["id1", "id2"], F: ["id1", "id2"], }, f6: { A: ["id1", "id2"], B: ["id1", "id2"], C: ["id1", "id2"], D: ["id1", "id2"], E: ["id1", "id2"], F: ["id1", "id2"], }, f7: { A: ["id1", "id2"], B: ["id1", "id2"], C: ["id1", "id2"], D: ["id1", "id2"], E: ["id1", "id2"], F: ["id1", "id2"], } }
Tests:
Hybrid
const e = (f, i, d) => { const c = _.get(fs, [f, i]); return c?.includes(d); }; e("f7", "F", "id2")
Lodash
const e = (f, i, d) => { const c = _.get(fs, [f, i]); return _.includes(c, d); }; e("f7", "F", "id2")
Native JS
const e = (f, i, d) => { const gf = fs[f]; const gfc = gf ? gf[i] : []; const fd = gfc?.includes(d); return fd || false; }; e("f7", "F", "id2")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Hybrid
Lodash
Native JS
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
llama3.2:3b
, generated one year ago):
I'll break down the benchmark definition and test cases to explain what's being tested, compared, and the pros and cons of each approach. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmark on the website MeasureThat.net. The benchmark is designed to measure the performance of three different approaches: Hybrid (using Lodash), Lodash, and Native JS. **Script Preparation Code** The script preparation code provides an object `fs` with multiple nested objects (`f1`, `f2`, ..., `f7`) containing arrays of strings (`A`, `B`, ..., `F`). This object is used to create a hierarchical data structure for testing. **Html Preparation Code** The HTML preparation code includes a link to Lodash.js, which will be used in the test cases. **Individual Test Cases** There are three test cases: 1. **Hybrid** * Benchmark Definition: Uses Lodash's `get` function to access the nested object and checks if a specific value (`d`) is included in the array. * Notes: This approach uses Lodash's functionality to navigate the hierarchical data structure, making it easier to write and maintain. 2. **Lodash** * Benchmark Definition: Uses Lodash's `includes` function to check if a specific value (`d`) is included in the array. * Notes: This approach relies solely on Lodash's `includes` function, which may not be as efficient as the Hybrid approach. 3. **Native JS** * Benchmark Definition: Uses native JavaScript to access the nested object and checks if a specific value (`d`) is included in the array. * Notes: This approach requires more manual code and may be less readable than the other two approaches. **Comparison** The test cases compare the performance of these three approaches on different hardware configurations (Firefox 79 on Mac OS X 10.15). The results show that: * Native JS is the fastest * Hybrid is slower but still performs well, likely due to Lodash's optimized implementation * Lodash is the slowest **Pros and Cons** 1. **Native JS** * Pros: Can be more efficient and optimal for specific use cases. * Cons: Requires more manual code and may be less readable. 2. **Hybrid (Lodash)** * Pros: Uses optimized Lodash implementation, making it faster than Native JS. * Cons: Relies on an external library, which may not be available or compatible with all environments. 3. **Lodash** * Pros: Can simplify code and reduce manual error-prone logic. * Cons: May be slower due to the overhead of using a separate library. **Best Practices** Based on these test results, it's recommended to use Native JS when: * Performance is critical * The data structure is simple and easy to access Use Hybrid (Lodash) when: * Readability and maintainability are more important than raw performance * You want to leverage optimized Lodash implementation Avoid using Lodash if: * You're working with complex or large datasets that may benefit from Native JS's optimization. Keep in mind that this is just a specific benchmark, and the best approach depends on the specific use case and requirements.
Related benchmarks:
Find item in large array - Fork
Test-BC
PlainJS vs Lodash
lodash isEmpty vs enumerating object keys
reassigning an object with larger arrray
Comments
Confirm delete:
Do you really want to delete benchmark?