Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Difference with test 2
(version: 5)
Comparing performance of:
Version 1 vs Version 2
Created:
5 years ago
by:
Registered User
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:
window.existingProperties = [ { "bmoId" : 9931265, "value" : { "type" : 5, "unit" : 1, "value" : "Level 1" }, "definition" : { "name" : "Global Level", "type" : 102, "flags" : 3, "group" : "BE_GLOBAL", "identifier" : "" } }, { "bmoId" : 9931264, "value" : { "type" : 5, "unit" : 1, "value" : "Generic - 200mm" }, "definition" : { "name" : "Global Name", "type" : 101, "flags" : 3, "group" : "BE_GLOBAL", "identifier" : "" } }, { "bmoId" : 9931263, "value" : { "type" : 5, "unit" : 1, "value" : "f4274632-54e9-4658-8b8b-30d6b2f5980bingo" }, "definition" : { "name" : "Global BIMEYE ID", "type" : 100, "flags" : 3, "group" : "BE_GLOBAL", "identifier" : "" } } ]; // we have one same property, one new and one is updated in sync window.newProperites = [ // updated property { "definition" : { "flags" : 3, "name" : "Global BIMEYE ID", "group" : "BE_GLOBAL", "type" : 100, "identifier" : "" }, "value" : { "value" : "f4274632-54e9-4658-8b8b-30d6b2f59801", "type" : 5, "unit" : 1 } }, // same property { "definition" : { "flags" : 3, "name" : "Global Name", "group" : "BE_GLOBAL", "type" : 101, "identifier" : "" }, "value" : { "value" : "Generic - 200mm", "type" : 5, "unit" : 1 } }, // new property { "definition" : { "flags" : 3, "name" : "kurcina ko greda", "group" : "BE_GLOBAL", "type" : 102, "identifier" : "" }, "value" : { "value" : "140000", "type" : 5, "unit" : 1 } } ]; window.accumulator = [];
Tests:
Version 1
var updateArray = []; var propertiesForDelete = _.intersectionWith(window.existingProperties, window.newProperites, (exp, np) => { // if props match all metadata and not value it's updated var conditionX = ( np.definition.flags === exp.definition.flags && np.definition.name === exp.definition.name && np.definition.group === exp.definition.group && np.definition.type === exp.definition.type && np.definition.identifier === exp.definition.identifier && np.value.type === exp.value.type && np.value.unit === exp.value.unit && np.value.value !== exp.value.value); if (conditionX) { updateArray.push(np); return true; } }); var removekey = 'bmoId' var keepKeys = ['definition', 'value']; // remove bmi key so we can match arrays var dummyArray = existingProperties.map(({bmoId, ...keepKeys}) => keepKeys); // find which properties are new var newPropsInSyncArray = _.differenceWith(_.differenceWith(window.newProperites, dummyArray, _.isEqual), updateArray, _.isEqual);
Version 2
var up2 = []; var del2 = []; var newPropsInSyncArrayMod = _.differenceWith(window.newProperites, window.existingProperties, (np, {bmoId, definition, value}) => { var conditionY = ( np.definition.flags === definition.flags && np.definition.name === definition.name && np.definition.group === definition.group && np.definition.type === definition.type && np.definition.identifier === definition.identifier && np.value.type === value.type && np.value.unit === value.unit); if (conditionY) { if (np.value.value !== value.value) { up2.push(np); del2.push({definition, value}); } return true; } return false; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Version 1
Version 2
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):
Measuring the performance of JavaScript benchmarks is an essential task in understanding how different approaches affect execution speed. **Benchmark Test:** The provided benchmark test compares the performance of two versions (Version 1 and Version 2) of a Lodash-based function for finding properties to update, delete, or keep in sync between two arrays (`window.existingProperties` and `window.newProperites`). The test checks which properties match all metadata (flags, name, group, type, identifier, and value) and have the same value. **Options Compared:** 1. **Version 1:** Uses `_.intersectionWith()` to find matching properties. 2. **Version 2:** Uses a custom comparison function (`(np, {bmoId, definition, value}) =>`) to filter out non-matching properties. **Pros and Cons of Each Approach:** * **Version 1 ( _.intersectionWith() ):** + Pros: - Simple and straightforward approach. - Efficient use of Lodash's built-in functionality. + Cons: - May be slower due to the overhead of using a third-party library. - Less flexible, as it relies on Lodash's specific implementation details. * **Version 2 ( Custom comparison function ):** + Pros: - More control over the filtering process. - Can potentially be optimized for performance. + Cons: - Requires more code and maintenance effort. - May introduce additional overhead due to custom logic. **Latest Benchmark Results:** The provided results show that: * **Version 2 (Custom comparison function)** outperforms **Version 1 ( _.intersectionWith() )** by approximately 57% in terms of executions per second. * Both versions are running on the same hardware and browser, making it more likely that the performance difference is due to the implementation details of each approach. In summary, while both approaches have their pros and cons, **Version 2 (Custom comparison function)** seems to be the faster choice in this specific benchmark. However, it's essential to consider the trade-offs between code complexity, maintainability, and performance when deciding which approach to use.
Related benchmarks:
instanceof vs hasOwnProperty2
Test on isEqual performance with array of objects and customiser
BasiaBasiaBasiaBasiaBasiaBasia
Lodash vs. direct comparison
equal vs assign vs defineProperty
Comments
Confirm delete:
Do you really want to delete benchmark?