const a = []
let b
for (let i = 0; i < 1e4; i++) a[i] = i
for (let i = 0; i < 1e4; i++) b = a[i]
const a = new Array(1e4)
let b
for (let i = 0; i < 1e4; i++) a[i] = i
for (let i = 0; i < 1e4; i++) b = a[i]
const a = new Int8Array(1e4)
let b
for (let i = 0; i < 1e4; i++) a[i] = i
for (let i = 0; i < 1e4; i++) b = a[i]
const a = new Set()
let b
for (let i = 0; i < 1e4; i++) a.add(i)
for (let i = 0; i < 1e4; i++) b = a.has(i)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
empty array | |
array 10000 | |
Int8Array | |
Set |
Test name | Executions per second |
---|---|
empty array | 40183.2 Ops/sec |
array 10000 | 77602.0 Ops/sec |
Int8Array | 68448.1 Ops/sec |
Set | 3471.1 Ops/sec |
Measuring JavaScript performance is an essential task for web developers, and MeasuringThat.net provides a great platform to do so.
Let's break down the benchmark definition and options being compared:
Benchmark Definition:
The benchmark measures the execution time of three different data structures in JavaScript:
Options Being Compared:
The benchmark compares the performance of these four options:
Pros and Cons of Each Approach:
Special JS Features/Syntax:
There are no special JavaScript features or syntax used in this benchmark. The focus is on comparing the performance of different data structures without introducing any additional complexity.
Library Usage:
None of the benchmark tests use external libraries. The code provided within each test case is self-contained and only relies on the built-in JavaScript data structures (arrays, sets).
Now, let's discuss alternative approaches to measuring JavaScript performance:
MeasuringThat.net's approach provides a simple and accessible way to compare the performance of different data structures, making it an excellent starting point for JavaScript performance benchmarking.