Skip to content

Instantly share code, notes, and snippets.

@igeligel
Created March 5, 2017 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igeligel/e78aa7fae225a19888ac667f34e13a25 to your computer and use it in GitHub Desktop.
Save igeligel/e78aa7fae225a19888ac667f34e13a25 to your computer and use it in GitHub Desktop.
jQuery Selector Performance
.block {
height: 50px;
background-color: black;
width: 500px;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery var test</title>
<meta name="description" content="jQuery var test">
<meta name="author" content="Kevin Peters">
<link rel="stylesheet" type="text/css" href="index.css">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="block"></div>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous">
</script>
<!--<script src="variable.js"></script>-->
<!--<script src="reselect.js"></script>-->
</body>
</html>
$(document).ready(function() {
for (var i = 0; i < 1000000; i++) {
$('.block').css('width', getRandomInt(100, 1500) + 'px');
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
});
$(document).ready(function() {
var block = $('.block')
for (var i = 0; i < 1000000; i++) {
block.css('width', getRandomInt(100, 1500) + 'px');
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment