Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Just
(version: 0)
Comparing performance of:
Lodash get vs Just get vs Lodash set vs Just set
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var person = {name: 'Frederick', lastName: 'Corcino Alejo', nested: {name: 'test'}}; function justGet(obj, propsArg, defaultValue) { if (!obj) { return defaultValue; } var props, prop; if (Array.isArray(propsArg)) { props = propsArg.slice(0); } if (typeof propsArg == 'string') { props = propsArg.split('.'); } if (typeof propsArg == 'symbol') { props = [propsArg]; } if (!Array.isArray(props)) { throw new Error('props arg must be an array, a string or a symbol'); } while (props.length) { prop = props.shift(); if (!obj) { return defaultValue; } obj = obj[prop]; if (obj === undefined) { return defaultValue; } } return obj; } function justSet(obj, propsArg, value) { var props, lastProp; if (Array.isArray(propsArg)) { props = propsArg.slice(0); } if (typeof propsArg == 'string') { props = propsArg.split('.'); } if (typeof propsArg == 'symbol') { props = [propsArg]; } if (!Array.isArray(props)) { throw new Error('props arg must be an array, a string or a symbol'); } lastProp = props.pop(); if (!lastProp) { return false; } prototypeCheck(lastProp); var thisProp; while ((thisProp = props.shift())) { prototypeCheck(thisProp); if (typeof obj[thisProp] == 'undefined') { obj[thisProp] = {}; } obj = obj[thisProp]; if (!obj || typeof obj != 'object') { return false; } } obj[lastProp] = value; return true; } function prototypeCheck(prop) { // coercion is intentional to catch prop values like `['__proto__']` if (prop == '__proto__' || prop == 'constructor' || prop == 'prototype') { throw new Error('setting of prototype values not supported'); } }
Tests:
Lodash get
_.get(person, 'name', ''); _.get(person, 'nested.name', '');
Just get
justGet(person, 'name', ''); justGet(person, 'nested.name', '');
Lodash set
_.set(person, 'nested.name.test', 'test'); _.set(person, 'name', 'test'); _.set(person, 'nested.name', 'test');
Just set
justSet(person, 'nested.name.test', 'test'); justSet(person, 'name', 'test'); justSet(person, 'nested.name', 'test');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash get
Just get
Lodash set
Just set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 17 on iOS 17.5.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash get
2372113.5 Ops/sec
Just get
1202943.6 Ops/sec
Lodash set
1186904.5 Ops/sec
Just set
765279.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the provided benchmark. **What is being tested?** The benchmark tests the performance of two JavaScript functions: `_.get` and `justGet`, which are part of the Lodash library, and their counterparts `_.set` and `justSet`. These functions are used to access and set properties on an object. **Options compared** The benchmark compares four different options: 1. **Lodash**: The `_.get` and `_.set` functions from Lodash, a popular JavaScript utility library. 2. **Just**: Two custom implementations of `get` and `set` functions, named `justGet` and `justSet`, respectively. **Pros and cons of each approach** 1. **Lodash**: Advantages: * Well-tested and widely used codebase. * Provides a robust implementation with features like support for nested properties and prototype checking. * Easy to use and integrate into existing projects. 2. Disadvantages: * Adds an extra dependency (the Lodash library) to the project. * May have overhead due to its size and complexity. 3. **Just**: Advantages: * Custom implementation, which can result in smaller binary size and potentially faster execution times. * Can be tailored to specific use cases or performance requirements. 4. Disadvantages: * Requires manual implementation of features like prototype checking and nested property support. * May have bugs or performance issues if not implemented correctly. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object manipulation, function composition, and more. The `_.get` and `_.set` functions are part of this library, which provide a convenient way to access and set properties on objects. **Special JS feature or syntax: Prototype checking** Prototype checking is a feature that allows developers to ensure that an object's prototype chain does not contain unwanted values or methods. In the context of the benchmark, prototype checking is used in both Lodash and Just implementations to prevent setting of prototype values. **Other alternatives** If you're looking for alternative libraries or approaches, some options include: 1. **Underscore.js**: Another popular JavaScript utility library that provides similar functions to Lodash. 2. **Ramda**: A functional programming library that provides a different set of utilities and abstractions. 3. **Custom implementation with a focus on performance**: You could attempt to implement the `get` and `set` functions from scratch, focusing on optimizing performance and avoiding unnecessary overhead. I hope this explanation helps! Let me know if you have any further questions or need clarification on specific points.
Related benchmarks:
Lodash.get vs Conditional property dot notation
lodash omit vs native function
lodas pick vs plain function
Lodash.get vs Lodash.property vs native test
Comments
Confirm delete:
Do you really want to delete benchmark?