var size = 50000;
var buf = new ArrayBuffer(size*8);
var view = new DataView(buf);
var data = new Float64Array(size);
for (let i=0; i < size; i++) {
view.setFloat64(i*8, 992.2258);
}
for (let i=0; i < size; i++) {
const res = view.getFloat64(i*8);
}
for (let i=0; i < size; i++) {
data[i] = 992.2258;
}
for (let i=0; i < size; i++) {
const res = data[i];
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
DataView | |
Float64Array |
Test name | Executions per second |
---|---|
DataView | 67.3 Ops/sec |
Float64Array | 66.6 Ops/sec |
Let's break down the provided benchmark definition and test cases to understand what's being tested.
What is being tested?
The provided benchmark measures the performance difference between two approaches for setting values in an ArrayBuffer using either a DataView or a Float64Array.
In more detail, the tests involve:
setFloat64()
method.toFloat64()
method.The second test case is similar, but instead of using a DataView, it uses a Float64Array directly to store and access the values.
Options compared
Two main options are being compared:
Pros and Cons
Library
None of the provided test cases rely on any external libraries. However, it's worth noting that DataView is an inherent feature of the JavaScript language and doesn't require additional library imports.
Special JS features/syntax
The tests do not utilize any special JavaScript features or syntax beyond what's described above (e.g., no async/await, no promises).
Other alternatives
Other alternatives for setting values in an ArrayBuffer could include:
However, these alternatives are not tested in the provided benchmark definition.
In summary, this benchmark compares two approaches for setting values in an ArrayBuffer: using a DataView and using a Float64Array directly. The tests evaluate the performance difference between these two methods, considering factors like data type conversion overhead and simplicity of usage.