ivapopova

jq_vs_es_profiling_demo.html

Oct 26th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Console APIs Demo</title>
  5.     <script
  6.  src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
  7.  integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E="
  8.  crossorigin="anonymous"></script>
  9.   <style type="text/css">
  10.     .box{
  11.         width: 50em;
  12.         height: 10em;
  13.         border: 2px solid #999;
  14.     }
  15.   </style>
  16. </head>
  17. <body>
  18.     <h2>Task: find which one will be faster using the console.time()?</h2>
  19.     <div class="box es">
  20.         <button>Color me with ES</button>
  21.     </div>
  22.     <div class="box jq">
  23.         <button>Color me with jQuery</button>
  24.     </div>
  25.  
  26. <script type="text/javascript">
  27.     repeat = 1000;
  28.  
  29.     $('.jq>button').click(function(){
  30.         for(let i = 0; i < repeat; i++){
  31.             $(this).parent().css('background',"red");
  32.         }
  33.         $(this).parent().css('background',"darkred");
  34.     })
  35.  
  36.     document.querySelector('.es>button').
  37.         addEventListener('click', function(){
  38.             for(let i = 0; i < repeat; i++){
  39.                 this.parentNode.style.backgroundColor = "blue";
  40.             }
  41.             this.parentNode.style.backgroundColor = "darkblue";
  42.         })
  43. </script>
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment