Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test performance aaaaa n
(version: 0)
Comparing performance of:
optimize 1 vs optimize 2
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const input = [ undefined, // empty data { hash: "a", amount: 1 }, undefined, // empty data { hash: "c", amount: 1 }, { hash: "b", amount: 3 }, undefined, // empty data { hash: "d", amount: 1 }, { hash: "b", amount: 1 }, { hash: "a", amount: 1 }, undefined, // empty data { hash: "f", amount: 3 }, { hash: "c", amount: 1 }, { hash: "d", amount: 1 }, { hash: "a", amount: 1 }, undefined, // empty data { hash: "e", amount: 3 }, { hash: "c", amount: 1 }, undefined, // empty data { hash: "k", amount: 1 }, undefined, // empty data { hash: "s", amount: 1 }, { hash: "b", amount: 3 }, undefined, // empty data { hash: "d", amount: 1 }, { hash: "c", amount: 1 }, { hash: "a", amount: 1 }, undefined, // empty data { hash: "f", amount: 3 }, { hash: "c", amount: 1 }, { hash: "d", amount: 1 }, { hash: "a", amount: 1 }, undefined, // empty data { hash: "e", amount: 3 }, { hash: "c", amount: 1 }, undefined, // empty data { hash: "a", amount: 1 }, undefined, // empty data { hash: "c", amount: 1 }, { hash: "s", amount: 3 }, undefined, // empty data { hash: "d", amount: 1 }, { hash: "b", amount: 1 }, { hash: "a", amount: 1 }, undefined, // empty data { hash: "h", amount: 3 }, { hash: "c", amount: 1 }, { hash: "d", amount: 1 }, { hash: "a", amount: 1 }, undefined, // empty data { hash: "e", amount: 3 }, { hash: "c", amount: 1 }, undefined, // empty data { hash: "a", amount: 1 }, undefined, // empty data { hash: "n", amount: 1 }, { hash: "b", amount: 3 }, undefined, // empty data { hash: "d", amount: 1 }, { hash: "b", amount: 1 }, { hash: "e", amount: 1 }, undefined, // empty data { hash: "f", amount: 3 }, { hash: "c", amount: 1 }, { hash: "d", amount: 1 }, { hash: "a", amount: 1 }, undefined, // empty data { hash: "e", amount: 3 }, { hash: "c", amount: 1 }, ]; function deferPromise(time) { new Promise((resolve) => setTimeout(resolve, time)); }
Tests:
optimize 1
async function main() { const arr = []; const mapHashByIndex = {}; let countBreaker = 0; await new Promise((resolve) => { input.forEach((item, index) => { console.log(typeof item, item); // break if empty data if (typeof item === "undefined") { countBreaker += 1; if (index === input.length - 1) resolve(); return; } // hash not exists in arr if (typeof mapHashByIndex[item.hash] === "undefined") { // insert to position arr[index - countBreaker] = item; mapHashByIndex[item.hash] = index - countBreaker; console.log("not found in mapHashByIndex ==> insert to " + (index - countBreaker)); } else { // this index not is first index of hash ? if (mapHashByIndex[item.hash] > index) { // insert to position = index - countBreaker arr.splice(index - countBreaker, 0, { ...arr[mapHashByIndex[item.hash]], amount: arr[mapHashByIndex[item.hash]].amount + item.amount, }); // remove position arr.splice(mapHashByIndex[item.hash], 1); // incr countBreaker countBreaker += 1; console.log( "found in mapHashByIndex, repalce index from " + mapHashByIndex[item.hash] + " to " + (index - countBreaker) ); // update new map mapHashByIndex[item.hash] = index - countBreaker; } else { arr[mapHashByIndex[item.hash]].amount += item.amount; console.log("found in mapHashByIndex, update amount of " + mapHashByIndex[item.hash]); // incr countBreaker countBreaker += 1; } } if (index === input.length - 1) resolve(); }); }); console.log(arr); } main();
optimize 2
async function main() { const arr = []; const mapHashByIndex = {}; let countBreaker = 0; await new Promise((resolve) => { input.forEach((item, index) => { console.log(typeof item, item); // break if empty data if (typeof item === "undefined") { countBreaker += 1; if (index === input.length - 1) resolve(); return; } // hash not exists in arr if (typeof mapHashByIndex[item.hash] === "undefined") { // insert to position arr[index - countBreaker] = item; mapHashByIndex[item.hash] = index - countBreaker; console.log("not found in mapHashByIndex ==> insert to " + (index - countBreaker)); } else { // this index not is first index of hash ? if (mapHashByIndex[item.hash] > index) { // incr countBreaker countBreaker += 1; // insert to position = index - countBreaker arr = arr.slice(0, index - countBreaker) concat([{ ...arr[mapHashByIndex[item.hash]], amount: arr[mapHashByIndex[item.hash]].amount + item.amount, }]) .concat(arr.slice(index - countBreaker, mapHashByIndex[item.hash])) .concat(arr.slice(mapHashByIndex[item.hash], arr.length)); console.log( "found in mapHashByIndex, repalce index from " + mapHashByIndex[item.hash] + " to " + (index - countBreaker) ); // update new map mapHashByIndex[item.hash] = index - countBreaker; } else { arr[mapHashByIndex[item.hash]].amount += item.amount; console.log("found in mapHashByIndex, update amount of " + mapHashByIndex[item.hash]); // incr countBreaker countBreaker += 1; } } if (index === input.length - 1) resolve(); }); }); console.log(arr); } main();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
optimize 1
optimize 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):
A long and complex benchmark result! After analyzing the data, I'll provide some general insights and suggestions for improvement. **Key observations:** 1. **Two versions of the benchmark**: The result shows two different implementations labeled as "optimize 1" and "optimize 2". It's likely that one version is an optimization over the other. 2. **High execution rates**: Both benchmarks achieved high execution rates, indicating fast performance. 3. **Low variance**: The executions per second values are relatively consistent, suggesting a good level of stability. **Potential areas for improvement:** 1. **Code duplication**: Some code blocks (e.g., `const arr = []`, `let countBreaker = 0`) appear to be duplicated across both implementations. Consider extracting these into separate functions or constants to reduce code duplication. 2. **Variable naming**: Variable names like `mapHashByIndex` and `arr` could be more descriptive, especially in the context of a benchmark. More informative names might help with code understanding and optimization efforts. 3. **Magic numbers**: The use of magic numbers (e.g., 114) for specific Chrome versions or device platforms may not be ideal. Consider using enums or constants to make the code more readable and maintainable. **Recommendations:** 1. Review both implementations carefully and identify opportunities for consolidation, simplification, or optimization. 2. Focus on readability and maintainability when optimizing the code. This will help ensure that any changes are beneficial and don't introduce new issues. 3. Consider using a testing framework to validate the optimized implementation and catch regressions. If you'd like more specific feedback or suggestions for improvement, please provide more details about the benchmarking context, such as: * What problem is being solved by this benchmark? * Are there any specific requirements or constraints that need to be met? I'll do my best to provide more targeted advice.
Related benchmarks:
array vs hashmap 2
array vs hashmap vs array-polling
array vs hashmap1 vs array-polling
Match 2 arrays, find vs fromEntries
set.add vs reduce
Comments
Confirm delete:
Do you really want to delete benchmark?