traditional castArray vs [].flat()

Benchmark created on


Setup

let fixtures = [
	[42, 37, 69],
	"Hello",
	[['a', 'b', 'c'], [99, 88, 77]]
];

let arrayify = Array.isArray(arr) ? arr : [arr];

Test runner

Ready to run.

Testing in
TestOps/sec
traditional castArray
for (const fixture of fixtures) {
	const result = arrayify(fixture);
	Array.isArray(result);
}
ready
[].flat
for (const fixture of fixtures) {
	const result = [fixture].flat();
	Array.isArray(result);	
}
ready

Revisions

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