Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
string to Uint8Array #5
copy bytes ascii string to Uint8Array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0
Browser:
Firefox 126
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
split + map + instance
727980.1 Ops/sec
split + forEach + set
345288.1 Ops/sec
for .. in loop
133670.0 Ops/sec
for .. of loop
126705.6 Ops/sec
Script Preparation code:
let repeat_count=5000; let pattern = 'abcdefgh'; var source = pattern.repeat(5);
Tests:
split + map + instance
const values = source.split('').map(c=>c.charCodeAt()); const res = new Uint8Array(values);
for .. in 1
const values = Array(source.length); for (let i in source) values[i]=source.charCodeAt(i); const res = new Uint8Array(values);
for .. in 2
const values = Array(); for (let i in source) values.push(source.charCodeAt()); const res = new Uint8Array(values);
classical loop
const values = Array(source.length); for (let i =0; i<source.length; i++) values[i]=source.charCodeAt(i); const res = new Uint8Array(values);
classical loop 2
const res = new Uint8Array(source.length); for (let i =0; i<source.length; i++) res[i]=source.charCodeAt(i);
for .. in loop 2
const res = new Uint8Array(source.length); for (let i in source) res[i]=source.charCodeAt(i);
split+forEach
const res = new Uint8Array(source.length); source.split('').forEach( (c,i) => res[i] = source.charCodeAt(i) )
for .. in loop 3
const res = new Uint8Array(source.length); for (let i in source) res[i]=source.charCodeAt(i);
for .. of loop 2
const res = new Uint8Array(source.length); let i=0; for (let c of source) res[i++]=c.charCodeAt();
from
const res = Uint8Array.from(source, c=>c.charCodeAt());
from + split
const res = Uint8Array.from(source.split(''), c=>c.charCodeAt());
TextEncoder
const res = new TextEncoder().encode(source)