Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
js reducing2
(version: 0)
Comparing performance of:
old method vs new method
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
fetch( 'https://fd-gmx-addin-dev.azurefd.net/assets/functions-typedoc.json' ).then((x) => x.json()).then(x => window.excelFunctions = x);
Tests:
old method
window.excelFunctions.reduce((categoryGroups, current) => { const categoryGroup = categoryGroups[current.category] || []; categoryGroups[current.category] = categoryGroup.concat(current); return categoryGroups; }, {});
new method
window.excelFunctions.reduce((categoryGroups, current) => { if (categoryGroups[current.category]) { categoryGroups[current.category].push(current); } else { categoryGroups[current.category] = [current]; } return categoryGroups; }, {});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
old method
new method
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 break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark is comparing two approaches to reducing an array of objects into a hierarchical structure, with each object representing a category group. The goal is to determine which approach is faster. **Script Preparation Code** The script preparation code fetches a JSON file from Azure that contains a list of functions. This JSON file is then used to populate the `window.excelFunctions` object, which is available in both test cases. **Benchmark Test Cases** There are two test cases: 1. **"old method"`**: This approach uses the traditional `reduce()` method, where it concatenates all objects with a matching category into an array. 2. **"new method"`**: This approach uses a conditional statement to check if the current object's category already exists in the `categoryGroups` object. If it does, it pushes the object onto the existing array; otherwise, it creates a new array for that category. **Library** The library being used is Excel Functions, which provides a set of functions for working with Excel data. In this case, the `reduce()` method is being used to group objects by their categories. **Special JavaScript Feature/Syntax** There isn't any special JavaScript feature or syntax being used in this benchmark that's worth noting. However, it's worth mentioning that the `fetch()` API is being used to load external data, which might not be supported in older browsers. **Pros and Cons of Approaches** 1. **"old method"`**: * Pros: Simple and easy to understand. * Cons: May lead to unnecessary array concatenation, resulting in slower performance for large datasets. 2. **"new method"`**: * Pros: More efficient use of memory, as it avoids unnecessary array concatenation. * Cons: Requires an extra conditional statement, which might add some overhead. **Considerations** When choosing between these approaches, consider the trade-off between simplicity and performance. If you prioritize readability and don't expect to work with large datasets, the "old method" might be sufficient. However, if you're working with large datasets or need optimal performance, the "new method" is likely a better choice. **Other Alternatives** If you were to rewrite this benchmark, you could consider other approaches, such as: 1. Using a more efficient data structure, like a `Map`, to group objects by category. 2. Using a library that provides optimized grouping functions, like Lodash. 3. Using a different algorithm altogether, like using a hash table or a trie. However, without seeing the updated benchmark code and test cases, it's difficult to provide more specific suggestions.
Related benchmarks:
js-map/obj
Fetch cache (default) vs no cache (no-store)
Parallel execution
Parallel execution 2
axios vs node-fetchV2
Comments
Confirm delete:
Do you really want to delete benchmark?