Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
continuous array vs sparse array
(version: 0)
Comparing performance of:
continuous reduce vs sparse reduce vs continuous update vs sparse update
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var continuous = []; var sparse = []; var C = 900000; for(var i=0; i<C; ++i){ continuous.push(C-i); } for(var i=0; i<C; ++i){ sparse[i * 2] = C - i; }
Tests:
continuous reduce
var total = continuous.reduce(function(acc, cur){ return acc + cur; });
sparse reduce
var total = sparse.reduce(function(acc, cur){ return acc + cur; });
continuous update
continuous.forEach(function(cur, i, arr){ arr[i] += 100; });
sparse update
sparse.forEach(function(cur, i, arr){ arr[i] += 100; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
continuous reduce
sparse reduce
continuous update
sparse update
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 its test cases. **Benchmark Definition:** The benchmark compares the performance of two types of arrays in JavaScript: 1. **Continuous array**: An array where every element is directly accessible by its index, without any holes or gaps. 2. **Sparse array**: An array where some elements are missing, represented as `undefined` values at those indices. The script preparation code creates a continuous array with 900,000 elements and a sparse array with the same number of elements, but with every other element being `undefined`. **Script Preparation Code:** ```javascript var continuous = []; var sparse = []; var C = 900000; for (var i = 0; i < C; ++i++) { continuous.push(C - i); } for (var i = 0; i < C; ++i) { sparse[i * 2] = C - i; } ``` This code initializes both arrays with the same elements, but the sparse array has every other element being `undefined`. **Test Cases:** The benchmark consists of four test cases: 1. **Continuous reduce**: Measures the performance of the `reduce()` method on the continuous array. 2. **Sparse reduce**: Measures the performance of the `reduce()` method on the sparse array. 3. **Continuous update**: Measures the performance of the `forEach()` method with a callback function that updates an element in the continuous array. 4. **Sparse update**: Measures the performance of the `forEach()` method with a callback function that updates an element in the sparse array. **Options Compared:** The benchmark compares two options: 1. **Reduce() method**: A built-in JavaScript method that reduces an array to a single value. 2. **ForEach() method**: A built-in JavaScript method that executes a callback function for each element in an array. **Pros and Cons:** * **Reduce() method**: + Pros: Efficient, vectorized, and can handle large datasets. + Cons: Can be less intuitive to use, especially for complex operations. * **ForEach() method**: + Pros: Easy to understand and use, allows for easy iteration and updating of elements. + Cons: Can be slower than the `reduce()` method, especially for large datasets. **Library Used:** The benchmark does not explicitly mention any libraries being used. However, it's likely that some underlying framework or runtime environment is providing the JavaScript engine and execution platform. **Special JS Feature/Syntax:** None mentioned in this specific benchmark. **Other Considerations:** * The benchmark uses a relatively small dataset (900,000 elements) to measure performance. * The benchmark runs on desktop devices with Chrome 93. * The benchmark reports executions per second, which provides an idea of the speedup or slowdown between different approaches. **Alternative Benchmarks:** If you're interested in exploring other benchmarking options, here are a few alternatives: 1. **Bench.js**: A popular JavaScript benchmarking library that allows for easy creation and comparison of benchmarks. 2. **Benchmarkify**: A utility library that simplifies the process of creating benchmarks and running them. 3. **Google's Benchmark**: A lightweight benchmarking library developed by Google, which provides a simple way to create and run benchmarks. Keep in mind that different benchmarking libraries may have varying levels of complexity, customization options, and performance characteristics.
Related benchmarks:
Object Indexed Properties (Read)
Sparse Array Vs. Object,Map,Set, Number Indexes
SparseSet - object literal vs class
Sparse Array Vs. Object, Map, Set, Number Indexes 2
Comments
Confirm delete:
Do you really want to delete benchmark?