Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uint8Array shallow cloning methods
(version: 1)
uint8Array shallow cloning methods
Comparing performance of:
slice() vs spread vs from() vs with()
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const uint8array = new Uint8Array(81); for(let i = 0; i < 81; i++) { uint8array[i] = Math.floor(Math.random() * 2); }
Tests:
slice()
for (let i; i < 1000; i++) { const copy = uint8array.slice(); r = Math.floor(Math.random() * 81); copy[r] ^= 1; }
spread
for (let i; i < 1000; i++) { const copy = [...uint8array]; r = Math.floor(Math.random() * 81); copy[r] ^= 1; }
from()
for (let i; i < 1000; i++) { const copy = TypedArray.from(uint8array); r = Math.floor(Math.random() * 81); copy[r] ^= 1; }
with()
for (let i; i < 1000; i++) { r = Math.floor(Math.random() * 81); const copy = uint8array.with(r, uint8array[r] ^ 1); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
slice()
spread
from()
with()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
slice()
91419064.0 Ops/sec
spread
102192776.0 Ops/sec
from()
100473248.0 Ops/sec
with()
81906104.0 Ops/sec
Related benchmarks:
Uint8Array vs Uint32Array
UInt8Array vs cast to array index access
UInt8Array vs cast to array index access 10k
JavaScript Array.slice vs Array.slice(0)
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes vs function
Array cloning
Cloning an array
copy ArrayBuffer: Uint8Array.set vs by bytes
uint8Array vs plain array, small, random get/set
Comments
Confirm delete:
Do you really want to delete benchmark?