Converting to Array

Benchmark created on


Setup

const arr = [1];
const single = 1;

function isArrayTernary(value) {
	return Array.isArray(value) ? value : [value];
}


function emptyConcat(value) {
	return [].concat(value);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array.isArray ternary
const fromArr = isArrayTernary(arr);
const fromSingle = isArrayTernary(single);


ready
[].concat
const fromArr = emptyConcat(arr);
const fromSingle = emptyConcat(single);
ready

Revisions

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