Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Extending ArrayBufferView
(version: 0)
How does extending an ArrayBufferView to add properties or functionality affect performance?
Comparing performance of:
Regular Array vs Uint Array vs Uint Array Expando vs Custom Array vs Custom Uint Array
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
class CustomArray extends Array { constructor(...args) { super(args); this.position = 0; } } class CustomUint8Array extends Uint8Array { constructor(...args) { super(args); this.position = 0; } } const LENGTH = 12000; var rArray = []; var uint8Array = new Uint8Array(LENGTH); var uint8ArrayExp = new Uint8Array(LENGTH); uint8ArrayExp.position = 0; var cArray = new CustomArray(LENGTH); var cUint8Array = new CustomUint8Array(LENGTH); for (let i = 0; i < LENGTH; i++) { const v = ~~(Math.random() * 255); rArray.push(v); uint8Array[i] = v; uint8ArrayExp[i] = v; cArray[i] = v; cUint8Array[i] = v; }
Tests:
Regular Array
function read(arr, offset) { let pos = offset; while (pos < arr.length) { pos++; if (arr[pos] < 127) { return pos; } } return pos; } let o = 0; while (o < rArray.length) { o = read(rArray, o); }
Uint Array
function read(arr, offset) { let pos = offset; while (pos < arr.length) { pos++; if (arr[pos] < 127) { return pos; } } return pos; } let o = 0; while (o < uint8Array.length) { o = read(uint8Array, o); }
Uint Array Expando
function read(arr) { while (arr.position < arr.length) { arr.position++; if (arr[arr.position] < 127) { return arr.position; } } return arr.position; } let o = 0; uint8ArrayExp.position = 0; while (o < uint8ArrayExp.length) { o = read(uint8ArrayExp); }
Custom Array
function read(arr) { while (arr.position < arr.length) { arr.position++; if (arr[arr.position] < 127) { return arr.position; } } return arr.position; } let o = 0; while (o < cArray.length) { o = read(cArray); }
Custom Uint Array
function read(arr) { while (arr.position < arr.length) { arr.position++; if (arr[arr.position] < 127) { return arr.position++; } } return arr.position; } let o = 0; while (o < cUint8Array.length) { o = read(cUint8Array, o); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Regular Array
Uint Array
Uint Array Expando
Custom Array
Custom Uint Array
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!
Related benchmarks:
Maping BooleanArray vs uInt8 Array2 vs uint8 with bitMasking _2
Maping numeric vs f32 vs f64
Extending ArrayBufferView with Properties
Maping numeric vs f32 vs f64 with add
Comments
Confirm delete:
Do you really want to delete benchmark?