Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
LodashBigStructure(VM1)
(version: 0)
teste
Comparing performance of:
Address Lodash vs Native
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var jsonEntity = {"ID":1,"MAINSOURCESYSTEM":null,"EXTERNALCODE":"VASCO1","NAME":"","FIRSTNAME":"Vasco","LASTNAME":"Mendes","SEARCHNAME1":"","SEARCHNAME2":"","CONTACTFORM":"Sr.","NIF":"211111111","COUNTRY":"Portugal","D":"","addresses":[{"ID":2,"BPID":1,"ADDRESS1":"Rua Morada 1 do Vasco","ADDRESS2":"Rua Morada 2 do Vasco","NUMBER":"nº 341","LOCALE":"Vale do Porto","POSTCODE":"2496-660","CITY":"Fátima","STATE":"Ourém-Santarém","COUNTRY":"Portugal","ISMAINADDRESS":true,"ISACTIVE":true,"VALIDFROM":"1900-01-01T00:00:00","VALIDTO":"1900-01-01T00:00:00","DESCRIPTION":"Morada principal"},{"ID":13,"BPID":1,"ADDRESS1":"Algarve em grande casas","ADDRESS2":"Junto ao mar","NUMBER":"No areal","LOCALE":"Algarve","POSTCODE":"2222-222","CITY":"Algarve","STATE":"","COUNTRY":"Portugal","ISMAINADDRESS":false,"ISACTIVE":true,"VALIDFROM":"1900-01-01T00:00:00","VALIDTO":"1900-01-01T00:00:00","DESCRIPTION":"Morada de Férias"}],"contacts":[{"ID":10,"BPID":1,"TYPE":1,"CONTACTNAME":"Vasco Mendes","CONTACTTITLE":"Sr,","CONTACT":"919999999","LANG":"PT","ISMAINCONTACTFORM":true,"ISMAINCONTACT":true,"ISACTIVE":true,"VALIDFROM":"1900-01-01T00:00:00","VALIDTO":"1900-01-01T00:00:00"},{"ID":11,"BPID":1,"TYPE":3,"CONTACTNAME":"Vasco","CONTACTTITLE":"Sr","CONTACT":"vasco.mendes@rupolusiaves.pt","LANG":"PT","ISMAINCONTACTFORM":false,"ISMAINCONTACT":false,"ISACTIVE":true,"VALIDFROM":"1900-01-01T00:00:00","VALIDTO":"1900-01-01T00:00:00"},{"ID":12,"BPID":1,"TYPE":2,"CONTACTNAME":"Responsável de departamento de compras","CONTACTTITLE":"","CONTACT":"+3519919191919","LANG":"PT","ISMAINCONTACTFORM":false,"ISMAINCONTACT":false,"ISACTIVE":true,"VALIDFROM":"1900-01-01T00:00:00","VALIDTO":"1900-01-01T00:00:00"}]};
Tests:
Address Lodash
_.get(jsonEntity, 'addresses[1].ADDRESS1');
Native
jsonEntity.addresses[1].ADDRESS1
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Address Lodash
Native
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 dive into the world of JavaScript benchmarks! **Benchmark Definition JSON** The provided JSON represents a benchmark definition for a test case named `LodashBigStructure(VM1)`. The main object contains information about the benchmark, such as its name and description. There are two child objects: `Script Preparation Code` and `Html Preparation Code`. However, in this case, both fields are empty (`null`). The key part of the benchmark is the array of individual test cases: ```json [ { "Benchmark Definition": "_.get(jsonEntity, 'addresses[1].ADDRESS1');\t", "Test Name": "Address Lodash" }, { "Benchmark Definition": "jsonEntity.addresses[1].ADDRESS1", "Test Name": "Native" } ] ``` These test cases are comparing the execution time of two different ways to access a property in an object: 1. Using Lodash's `_.get()` function, which is a utility function for safely navigating and retrieving values from objects. 2. Directly accessing the property using dot notation (`jsonEntity.addresses[1].ADDRESS1`). **Options Comparison** Let's analyze the pros and cons of each approach: ### Lodash's _.get() function Pros: * **Safety**: `_get()` is designed to prevent null pointer exceptions by checking if the object and path exist. * **Flexibility**: Can handle nested objects and paths with wildcards (e.g., `_.get(obj, 'a.b[c]')`). Cons: * **Overhead**: Using a dedicated function for simple operations can introduce additional overhead due to the function call and potential checks. ### Direct Access Pros: * **Speed**: Direct access is typically faster since it involves only a single property lookup. * **Simplicity**: The code is straightforward and easy to understand. Cons: * **Safety**: Directly accessing properties without checks can lead to null pointer exceptions or errors if the object doesn't exist. **Library: Lodash** Lodash is a popular JavaScript library that provides a wide range of utility functions for tasks like array manipulation, object traversal, and more. The `_get()` function is one of its most useful utilities, allowing you to safely navigate objects and retrieve values. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntax used in these test cases. **Other Alternatives** If you need to traverse nested objects, other alternatives might include: * Using a library like `json-path` to specify paths for object traversal. * Implementing your own recursive function for traversing objects. * Utilizing modern JavaScript features like destructuring assignment and `Object.prototype.hasOwnProperty.call()` for safe property access. Keep in mind that the choice of approach depends on the specific requirements of your project, such as performance, safety, and code readability.
Related benchmarks:
test lodash vs js vanilla
LodashBigStructure
lodash clonedeep vs json.parse(stringify())
Lodash cloneDeep vs native cloneDeep fdasfff
Comments
Confirm delete:
Do you really want to delete benchmark?