Return to Snippet

Revision: 15390
at July 3, 2009 07:17 by 1man


Initial Code
$(function(){
	console.info("Start Test");
	var d = new Date();//Get our start time
	console.info(d.getSeconds() + " " + d.getMilliseconds());
	
	//Run our test
	var testBody = "";
	for (var i=0; i<1000; i++){
		testBody += "<div class='testable"+i+"'>";
	}
	$("body").append(testBody);
	for (var j=0; j<1000; j++){
		$(".testable"+j);
	}
	
	var d = new Date();//Get our end time
	console.info(d.getSeconds() + " " + d.getMilliseconds());
	console.info("End Test");
	/**
	 * Console will now log 2 times, the difference between 
	 * them is how long the test took to run
	 */
});

Initial URL
http://is.gd/1mhJr

Initial Description
A way to time how long it takes to get through a certain block of code. Good way to measure performance on the page.

You could also use the built in logging functions in firebug. Not sure how they would tally up in a test.

Initial Title
Function Timing Example (includes jQuery)

Initial Tags
function

Initial Language
jQuery