JavaScript Performance Tester

Tests performance of different JavaScript Functions and prints the results to the console.

HTML

<input id="runTests" type="button" value="Run Tests"/>
<div id="testOutput"/>

JavaScript

var SECONDS_PER_TEST = 5;
var MS_PER_TEST = SECONDS_PER_TEST * 1000;
var MAX_TESTS_TO_RUN = 10000;

var a = [];

var initializeTest = function(){
    
};


 function camelCaseToDash(input){
         return input.replace(/([A-Z])/g, '-$1').toLowerCase(); 
    }    
    
    //or
    function camelCaseToDash2(input){
         return input.replace(/([A-Z])/g, (x)=> "-"+ x.toLowerCase());
    }    

var tests = {
    test2Step: function(){
        camelCaseToDash("adfIasdfkIKdfaKeafdDfadfDfefDve");
    },
    testCallback: function(){
        camelCaseToDash2("adfIasdfkIKdfaKeafe");
    },
};


var runTests = function(){
    var testTimes = {};
    for(var testName in tests){
        testTimes[testName] = runTest(testName, tests[testName]);
    }
    
    var minTestTime = 10000;
    for(var testName in testTimes){
        var testTime = testTimes[testName];        
        if(testTime < minTestTime){
            minTestTime = testTime;
        }
    }
    
    console.log('\nTest Results:');
    for(var testName in testTimes){
        var testTime = testTimes[testName];        
        if(testTime == minTestTime){
            console.log('  ' + testName + ':  Fastest!');
        } else {
            var percent = ((testTime / minTestTime) - 1) * 100
            var percentDisplay = parseFloat(percent).toFixed(2)
            console.log('  ' + testName + ':  ' + percentDisplay + '% slower');
        }
    }
};

var runTest = function(testName, testFunction){
    console.log('Testing ' + testName + '... (please wait ' + SECONDS_PER_TEST + ' seconds)');
    
    //Run once to see how many times we should run the test
    var startTime = getTime();
    var testRuns = totalTestTime = 0;
    while((getTime() - startTime) < MS_PER_TEST){
        initializeTest();
        
        var testTimeStart = getTime();
        testFunction();
        totalTestTime += getTime() - testTimeStart;
        
        testRuns++;
    }
    
    //Output and return the results
    var...