Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Kolbey's test
(version: 0)
Comparing performance of:
_.set vs regular assign
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var o = {c:3,d:4}
Tests:
_.set
_.set(o, 'a') _.set(o, 'b')
regular assign
o.a = 1; o.b = 2;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.set
regular assign
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):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is defined by two scripts: 1. `var o = {c:3,d:4}` - This script prepares an object `o` with two properties, `c` and `d`, both initialized to 3 and 4 respectively. 2. `_.set(o, 'a')\r\n_.set(o, 'b')` - This script calls the `_set` function from the Lodash library on the object `o`. The `_set` function sets a value for a given key in the object. **Options Compared** The benchmark compares two approaches: 1. **Regular Assignment**: `o.a = 1;\r\no.b = 2;` 2. **Lodash's `_set` Function**: `_.set(o, 'a')\r\n_.set(o, 'b')` **Pros and Cons of Each Approach** 1. **Regular Assignment**: * Pros: Simple, fast, and efficient. * Cons: May not be as readable or maintainable for complex assignments. 2. **Lodash's `_set` Function**: * Pros: Provides a way to set values in an object without directly modifying the original object. * Cons: Adds overhead due to function call and may not be as fast as direct assignment. **Other Considerations** * The benchmark uses Lodash library, which provides a utility function for setting values in objects. This library is not included in the JavaScript core and adds extra complexity to the benchmark. * There are no special JavaScript features or syntax being tested in this benchmark. **Alternative Approaches** Other approaches to set values in an object could include: 1. Direct assignment: `o.a = 1;\r\no.b = 2;` (as shown in the benchmark) 2. Using a property descriptor: `{ [Symbol.for('a')]: 1, [Symbol.for('b')]: 2 }` 3. Using a library like Immutable.js or Ramda, which provide immutable data structures and functions for setting values. Overall, the benchmark is testing the performance of two approaches to set values in an object: regular assignment versus using Lodash's `_set` function.
Related benchmarks:
hasVshasOwnProperty
lodash slice
isEmpty vs. vanilla
empty arr
Last Lodash Test
Comments
Confirm delete:
Do you really want to delete benchmark?