Skip to content

Instantly share code, notes, and snippets.

@ellisio
Created May 17, 2011 20:40
Show Gist options
  • Save ellisio/977342 to your computer and use it in GitHub Desktop.
Save ellisio/977342 to your computer and use it in GitHub Desktop.
<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