String to char array (v2)

Revision 2 of this benchmark created on


Setup

function randStr(length) {
    let result = '';
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    const charactersLength = characters.length;
    let counter = 0;
    while (counter < length) {
      result += characters.charAt(Math.floor(Math.random() * charactersLength));
      counter += 1;
    }
    return result;
}

let loopLength = 2000;
let str;

Test runner

Ready to run.

Testing in
TestOps/sec
String.split('')
for(let i=0; i<loopLength; ++i){
	str = randStr(300);
	str = str.split('');
}
ready
spread operator [...String]
for(let i=0; i<loopLength; ++i){
	str = randStr(300);
	str = [...str];
}
ready
Array.from(String)
for(let i=0; i<loopLength; ++i){
	str = randStr(300);
	str = Array.from(str);
}
ready
Object.assign([], String)
for(let i=0; i<loopLength; ++i){
	str = randStr(300);
	str =  Object.assign([],str);
}
ready
Regex .match(/./g)
for(let i=0; i<loopLength; ++i){
	str = randStr(300);
	str =  str.match(/./g);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.