SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function test() {
  2.   const array = [];
  3.  
  4.   for (let i = 0; i < 10000000; i++) {
  5.     array.push(Math.random());
  6.   }
  7.  
  8.   console.time("For");
  9.   for (let i = 0; i < array.length; i++) {
  10.     array[i] * 10;
  11.   }
  12.   console.timeEnd("For");
  13.  
  14.   console.time("For of");
  15.   for (let item of array) {
  16.     item * 10;
  17.   }
  18.   console.timeEnd("For of");
  19.  
  20.   console.time("For each");
  21.   array.forEach(item => {
  22.     item * 10;
  23.   });
  24.   console.timeEnd("For each");
  25. }
  26.  
  27. for (let i = 0; i < 10; i++) {
  28.   test();
  29.   console.log("--------");
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top