let array = [];
for (let i = 0 ; i < 10 ; i++) {
const index = Math.floor (Math.random () * 10);
array[index] = 1;
}
let object = {};
for (let i = 0 ; i < 10 ; i++) {
const index = Math.floor (Math.random () * 10);
object[index] = 1;
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array | |
Object |
Test name | Executions per second |
---|---|
Array | 231394.4 Ops/sec |
Object | 214557.5 Ops/sec |
Let's dive into the world of MeasureThat.net and explore what's being tested in this specific benchmark.
What is being tested?
The provided benchmark compares two approaches: creating an array versus creating an object using JavaScript. The test cases are designed to measure which approach is faster when:
The benchmark definition json specifies the script preparation code and HTML preparation code, which are left blank in this case. This means that the only thing being executed is the JavaScript code provided in the Benchmark Definition
section.
Options compared
Two options are being compared:
Pros and Cons of each approach:
Special JS features or syntax
In this benchmark, no special JavaScript features or syntax are being tested. The code provided is standard JavaScript that can be run in any compatible environment.
Library usage
Neither of the test cases uses a specific library, so there's nothing to report on in terms of library usage.
Other considerations
When measuring the performance of array vs object creation, other factors such as:
These are interesting considerations when benchmarking these approaches.
Other alternatives
If you're interested in exploring other benchmarks, here are some alternatives: