Last active
February 6, 2022 12:26
-
-
Save sandeep-cs-dev/a2c7293c0d63d12359a03cc4bfe8af99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.time('eventlooplag'); | |
| //event-loop timer phase | |
| setTimeout(() =>console.timeEnd('eventlooplag'), 100); | |
| /*blocking code, stalling event loop, delaying the execution of the setTimeout ie lag in the event loop | |
| */ | |
| const min = 2; | |
| const max = 3e6; | |
| const primes = []; | |
| function generatePrimes(start, range) { | |
| let isPrime = true; | |
| let end = start + range; | |
| for (let i = start; i < end; i++) { | |
| for (let j = min; j < Math.sqrt(end); j++) { | |
| if (i !== j && i%j === 0) { | |
| isPrime = false; | |
| break; | |
| } | |
| } | |
| if (isPrime) { | |
| primes.push(i); | |
| } | |
| isPrime = true; | |
| } | |
| } | |
| generatePrimes(min, max); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment