Testing IIFE Alias Performance

^ title

by JordanForeman

HTML

<h3>IIFE Execution Times <small>(in ms)</small></h3>
<strong>No Aliases: </strong><span id="a-timer"></span>ms
<br />
<strong>W/ Aliases: </strong><span id="b-timer"></span>ms
<br />
<strong>Perf Diff: </strong><span id="improvement"></span>ms

<i id="hook"></i>

JavaScript

// Testing execution speeds of varying common JS tasks using IIFEs with/without Aliased $Globals
var rotations = 10000000,
    aExecTime = 0,
    bExecTime = 0;

(function(){
    var start = new Date().getMilliseconds(),
        i = 0;
    for (i; i < rotations; i++){
        // Code to speedtest
    	document.getElementById('hook');
    }
	var end = new Date().getTime();
   	aExecTime = end - start;

	document.getElementById('a-timer').innerHTML = aExecTime;
    
}());

(function(window, document){

    var start = new Date().getMilliseconds(),
        i = 0;
    for (i; i < rotations; i++){
        // Code to speedtest
    	document.getElementById('hook');
    }
	var end = new Date().getTime();
   	bExecTime = end - start;

	document.getElementById('b-timer').innerHTML = bExecTime;

}(window, document));

document.getElementById('improvement').innerHTML = bExecTime - aExecTime;