JSFiddle - React, Tailwind, and code Playground
JavaScript
// Runs a function many times without the function call overhead
function benchmark(fn, times){
fn = fn.toString();
var s = fn.indexOf('{')+1,
e = fn.lastIndexOf('}');
fn = fn.substring(s,e);
return new Function('i','var t=new Date;while(i>=0){'+fn+'i--;}return new Date-t;')(times);
}
function a(){
var p = new Array(1, 2, 3);
}
function b(){
var q = [1, 2, 3];
}
var perTest = 10000000;
var numTests = 20;
var testResults = [0, 0, 0, 0];
var functionCalls = numTests*perTest;
testResults[0] += benchmark(a, functionCalls);
testResults[1] += benchmark(b, functionCalls);
console.group('Average speed per ' + perTest + ' calls');
console.log('Array Constructor : ' + testResults[0]/numTests);
console.log('Array Literal : ' + testResults[1]/numTests);
console.groupEnd();