<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/12.1.0/radash.min.js" integrity="sha512-JEUqDJrck58H46FvJVzwvDWVlVEF83BkaG8/fagfTApgdo8ERV+Hqx4t7rDyFN8JGv84+r+WNoq9oZsgi5Glhw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
var obj = {a: {b: {c: {d: 1}}}}
var badObj = {}
var c = obj.a == null ? undefined : obj.a.b == null ? undefined : obj.a.b.c == null ? undefined : obj.a.b.c.d
c == null ? 2 : c
var d = badObj.a == null ? undefined : badObj.a.b == null ? undefined : badObj.a.b.c == null ? undefined : badObj.a.b.c.d
d == null ? 2 : d
_.get(obj, "a.b.c.d", 2)
_.get(badObj, "a.b.c.d", 2)
radash.get(obj, "a.b.c.d", 2)
radash.get(badObj, "a.b.c.d", 2)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Optional | |
lodash | |
radash |
Test name | Executions per second |
---|---|
Optional | 157087600.0 Ops/sec |
lodash | 7242380.0 Ops/sec |
radash | 3008434.0 Ops/sec |
Let's break down the benchmark and its test cases.
Benchmark Definition
The benchmark is comparing two JavaScript libraries, Lodash (also known as "lodash") and Radash (also known as "radash"). The benchmark definition json provides information about the script preparation code, which sets up two objects: obj
and badObj
. obj
is a nested object with multiple levels of properties, while badObj
is an empty object.
Options Compared
The two libraries being compared are:
_.get()
)radash.get()
)These functions are used to access the value of a nested property in both objects. The benchmark definition provides the exact code snippets for each library, which allows users to run the same test cases with different libraries.
Pros and Cons
.get()
function is optimized for performance and is often used in production code.get()
function is also well-optimized and efficient.Other Considerations
=>
) and template literals (```). This means that users need to be comfortable with ES6 syntax to run the benchmark.Libraries
Special JS Features/Syntax
None mentioned in the benchmark definition.
Alternatives
If you're looking for alternatives to Lodash or Radash, here are some popular options:
Keep in mind that each library has its strengths and weaknesses, and the choice of which one to use depends on your specific project requirements and constraints.