event.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Test Event Handling 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(){
  11. });
  12. var events = [], num = 400, exec = false;
  13. jQuery(document).mousemove(function(e){
  14. if ( exec ) {
  15. return;
  16. }
  17. if ( events.length >= num ) {
  18. exec = true;
  19. var s = (new Date).getTime();
  20. for ( var n = 0; n < 5; n++ ) {
  21. for ( var i = 0; i < num; i++ ) {
  22. old.event.handle.call( document, events[i] );
  23. }
  24. }
  25. var oldNum = (new Date).getTime() - s;
  26. s = (new Date).getTime();
  27. for ( var n = 0; n < 5; n++ ) {
  28. for ( var i = 0; i < num; i++ ) {
  29. jQuery.event.handle.call( document, events[i] );
  30. }
  31. }
  32. var curNum = (new Date).getTime() - s;
  33. jQuery("#num").text( old.fn.jquery + ": " + oldNum + " " + jQuery.fn.jquery + ": " + curNum );
  34. jQuery(this).unbind( "mousemove", e.handler );
  35. } else {
  36. events.push( e.originalEvent );
  37. jQuery("#num").text( events.length + " / " + num );
  38. }
  39. });
  40. </script>
  41. </head>
  42. <body>
  43. <p>Move the mouse, please!</p>
  44. <p id="num"></p>
  45. </body>
  46. </html>