var length = 1e6;
var f32_a = Float32Array.from({length}, Math.random);
var f32_b = Float32Array.from({length}, Math.random);
var f64_a = Float64Array.from({length}, Math.random);
var f64_b = Float64Array.from({length}, Math.random);
var arr_a = Array.from({length}, Math.random);
var arr_b = Array.from({length}, Math.random);
f32_a.set(f32_b);
f64_a.set(f64_b);
for (let i = 0; i < length; i++) {
f32_a[i] = f32_b[i];
}
for (let i = 0; i < length; i++) {
f64_a[i] = f64_b[i];
}
for (let i = 0; i < length; i++) {
arr_a[i] = arr_b[i];
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
set f32 | |
set f64 | |
iterate and set f32 | |
iterate and set f64 | |
iterate and set array |
Test name | Executions per second |
---|---|
set f32 | 3764.5 Ops/sec |
set f64 | 1237.4 Ops/sec |
iterate and set f32 | 169.9 Ops/sec |
iterate and set f64 | 169.6 Ops/sec |
iterate and set array | 190.6 Ops/sec |
What is being tested?
MeasureThat.net is testing the performance of different data types (Float32, Float64, and Array) in JavaScript for common operations:
set()
Options compared
The benchmark compares three options:
Pros and Cons
Here's a brief overview of the pros and cons of each option:
Libraries and special JS features
None of the test cases use libraries or special JavaScript features that would impact their behavior. The focus is solely on comparing the performance of different data types.
Other alternatives
If you wanted to add more options to the benchmark, you could consider:
Keep in mind that adding new options would require updating the benchmark script and ensuring compatibility with various browsers and environments.