Forked from CezaryDanielNowak/script-performance-test.js
Created
October 8, 2013 14:30
-
-
Save ruslansavenok/6885641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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