Created
May 17, 2011 20:40
-
-
Save ellisio/977342 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
<html> | |
<head> | |
<title>Test</title> | |
</head> | |
<body> | |
<div id="object"> | |
<div class="box"></div> | |
</div> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script> | |
<script type="text/javascript"> | |
var i = 0; | |
var time = 0; | |
var timer = function(action) { | |
var d = new Date(); | |
if (time < 0 || action == 'start') { | |
var time = d.getTime(); | |
return 0; | |
} else if (action == 'stop') { | |
var t = d.getTime() - time; | |
var time = 0; | |
return t; | |
} else { | |
return d.getTime() - time; | |
} | |
}; | |
$(function(){ | |
var $object = $('#object'); | |
timer('start'); | |
while (i < 100000) { | |
$('.box', $object); | |
++i; | |
} | |
console.log(timer('stop')); | |
i = 0; | |
timer('start'); | |
while(i < 100000) { | |
$object.find('.box'); | |
++i; | |
} | |
console.log(timer('stop')); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment