closest.html 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Test .closest() Performance</title>
  5. <script src="benchmark.js"></script>
  6. <script src="jquery-basis.js"></script>
  7. <script>var old = jQuery.noConflict(true);</script>
  8. <script src="../dist/jquery.js"></script>
  9. <script>
  10. jQuery(function ready() {
  11. var node = $("#child"), name;
  12. jQuery.each([".zoo", "#zoo", "[data-foo=zoo]", "#nonexistant"], function(i, item) {
  13. setTimeout(function(){
  14. name = "closest '" + item + "'";
  15. jQuery("#results").append("<li>" + name + "<ul>" +
  16. "<li>new: " + benchmarkString("$('#child').closest('" + item + "')", 2500, name) + "</li>" +
  17. "<li>old: " + benchmarkString("old('#child').closest('" + item + "')", 2500, name) + "</li>"
  18. + "</ul></li>");
  19. }, 100);
  20. });
  21. });
  22. </script>
  23. </head>
  24. <body>
  25. <div>
  26. <p>Hello</p>
  27. <div class="zoo" id="zoo" data-foo="bar">
  28. <div>
  29. <p id="child">lorem ipsum</p>
  30. <p>dolor sit amet</p>
  31. </div>
  32. </div>
  33. </div>
  34. <ul id="results"></ul>
  35. </body>
  36. </html>