<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var obj = {
description: 'Creates a deep copy of source, which should be an object or an array.',
myNumber: 123456789,
myBoolean: true,
jayson: {
stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....',
parse: 'JSON.parse() method parses a JSON string...'
}
};
const values = _.get(obj, 'jayson')
const values = obj.jayson
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
LODASH | |
JS |
Test name | Executions per second |
---|---|
LODASH | 3646391.0 Ops/sec |
JS | 14671711.0 Ops/sec |
I'd be happy to help you understand the JavaScript microbenchmark provided by MeasureThat.net.
Benchmark Definition
The benchmark definition is a JSON object that represents the test case being performed. In this case, there are two benchmark definitions:
"GET vs _GET"
: This is not a traditional benchmarking scenario, but rather an introduction to the concept of benchmarks on MeasureThat.net. It doesn't provide any specific code or functionality."LODASH"
: Tests the performance of accessing a nested object property using Lodash's _.get()
method."JS"
: Tests the performance of accessing a nested object property without using Lodash.Options Compared
The two options compared are:
_.get()
method to access a nested object property (LODASH
).JS
).Pros and Cons of Each Approach
.get()
method):Library: Lodash
Lodash is a popular JavaScript utility library that provides various functions for common tasks, such as:
In this benchmark, Lodash's _.get()
method is used to access the nested object property jayson.stringify
. The _
symbol refers to the Lodash namespace.
Special JS Feature/Syntax
There isn't any special JavaScript feature or syntax mentioned in this benchmark. However, it's worth noting that MeasureThat.net may use other features, such as async/await
, promises
, or modern language features like const
and let
, to create more realistic benchmarks.
Other Alternatives
If you prefer not to use Lodash or want to explore alternative approaches, here are a few options:
obj.jayson
): This approach eliminates the need for an additional library or function.Keep in mind that these alternatives might require more manual effort to implement and maintain, especially for complex property paths.