Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Getters
(version: 0)
Comparing performance of:
Lodash vs Mine vs Rambda
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js'></script>
Script Preparation code:
function getProp(property) { var selector = typeof property === 'string' ? property.split('.') : property return (obj) => selector.reduce((newObj, currentProp) => { if (newObj[currentProp]) { newObj = newObj[currentProp] return newObj } }, obj) } function path(list, obj){ if (arguments.length === 1) return _obj => path(list, _obj) if (obj === null || obj === undefined){ return undefined } let willReturn = obj let counter = 0 const pathArrValue = typeof list === 'string' ? list.split('.') : list while (counter < pathArrValue.length){ if (willReturn === null || willReturn === undefined){ return undefined } willReturn = willReturn[ pathArrValue[ counter ] ] counter++ } return willReturn } var obj = { a: { b: { c: { foo: { bar() { return '42' } } } } } }
Tests:
Lodash
_.get(obj, 'a.b.c.foo.bar')
Mine
getProp('a.b.c.foo.bar')(obj)
Rambda
path('a.b.c.foo.bar')(obj)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Mine
Rambda
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):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test, where three different approaches (Lodash, Mine, and Rambda) are compared for accessing nested properties in an object. **What is being tested?** The benchmark tests the performance of three functions: 1. **Lodash**: The `_.get()` function from Lodash library, which provides a convenient way to access nested properties in objects. 2. **Mine**: A custom implementation (not shown) that accesses nested properties using a recursive approach. 3. **Rambda**: A library (Rambda.js) that provides a functional programming style for accessing nested properties. **Options compared** The three approaches differ in their implementation details: 1. **Lodash**: Uses the `_.get()` function, which takes an object and an array of property names as arguments. It recursively traverses the object using the provided property names. 2. **Mine**: Uses a custom recursive approach to access nested properties, as shown in the script preparation code. This implementation is not part of any popular library. 3. **Rambda**: Uses Rambda's `path()` function, which takes an array of property names and an object as arguments. It also recursively traverses the object using the provided property names. **Pros and Cons** Here are some pros and cons of each approach: 1. **Lodash**: * Pros: Convenient, widely used, and well-maintained library. * Cons: Adds extra overhead due to the use of a separate library. 2. **Mine**: * Pros: Custom implementation allows for fine-grained control over performance optimization. * Cons: Requires manual management of recursive function calls, which can lead to performance issues if not implemented correctly. 3. **Rambda**: * Pros: Provides a functional programming style, making it easier to reason about the code and optimize its performance. * Cons: Requires knowledge of Rambda's API and may have a learning curve. **Library usage** In this benchmark, Lodash is used via an HTML script tag, which loads the library. Mine is not part of any popular library, and Rambda.js is also loaded as an external script. **Special JavaScript features or syntax** None of the implementations use any special JavaScript features or syntax that would impact performance. The focus is on the recursive traversal of nested properties in objects. **Other alternatives** Other approaches to accessing nested properties might include: 1. **Destructuring**: Using destructuring assignment (e.g., `const obj = { a: { b: { c: 'foo' } } }; const [a, b, c] = Object.values(obj)`). 2. **For loops**: Using traditional for loops to iterate over the object's properties. 3. **Object iteration**: Iterating over the object's own enumerable properties using `for...in` or `for...of`. These alternatives might offer different performance characteristics and trade-offs in terms of readability, maintainability, and functionality.
Related benchmarks:
Get props
Get props
lodash set vs custom set
Lodash.get vs Lodash.property vs native test
Comments
Confirm delete:
Do you really want to delete benchmark?