Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ruslansavenok/6885641 to your computer and use it in GitHub Desktop.
Save ruslansavenok/6885641 to your computer and use it in GitHub Desktop.
var testReplies = 10000,
testCode = function() {
/* code to test */
//$(this) is #actionBox, use it as your container
//#actionBox that will be removed after test
},
actionBoxConfigure = function(){
/* put elements into actionBox here */
//var i=100;
//while(i-- > 0)
// $(this).append('<div class="sth">');
};
var testFunction = function() {
var tmpReplies = testReplies,
actionBox = jQuery('<div id="actionBox" style="position:absolute;top:-9999px"></div>').appendTo(document.body);
actionBoxConfigure.call(actionBox[0]);
var timeStart = new Date().getTime();
while(tmpReplies-- > 0)
testCode.call(actionBox[0]);
var timeEnd = new Date().getTime();
actionBox.remove()
/* OUTPUT: */
var getDate = function() {
var date = new Date();
return date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).slice(-2) +'-'+('0'+date.getDate()).slice(-2)+ ' ' + ('0'+date.getHours()).slice(-2) + ':' + ('0'+date.getMinutes()).slice(-2) + ':' + ('0'+date.getSeconds()).slice(-2);
};
return getDate() + ': '
+ testCode.toSource().length + ' bytes of code, '
+ testReplies + ' replies in '
+ ((timeEnd - timeStart)/1000) + ' seconds';
};
if(window.jQuery) {
testFunction();
} else {
var s = document.createElement('script');
s.onerror = function() {
console.log("Can't load jQuery");
};
s.onload = function() {
console.log(testFunction());
};
s.setAttribute('src','http://code.jquery.com/jquery-latest.min.js');
document.getElementsByTagName('head')[0].appendChild(s);
'Loading jQuery...';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment