Created
          August 26, 2020 06:51 
        
      - 
      
- 
        Save jasonsturges/a3f4e2a6696647084cbc49abdff918f8 to your computer and use it in GitHub Desktop. 
    Benchmarking JavaScript - Asynchronous execution
  
        
  
    
      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
    
  
  
    
  | const runTest = (iterations = 100000000) => { | |
| let startTime = new Date().getTime(); | |
| for (let i = 0; i < iterations; i++) | |
| Math.log10(0) | |
| let endTime = new Date().getTime(); | |
| let totalTime = endTime - startTime; | |
| let fnTime = (totalTime / iterations).toFixed(10); | |
| let operations = Math.floor(1000 / totalTime * iterations); | |
| console.log(`total: ${totalTime}, time: ${fnTime}, op/sec: ${operations}`); | |
| } | |
| while (true) { | |
| runTest(); | |
| await sleep(50); | |
| } | |
| function sleep(ms) { | |
| return new Promise(resolve => setTimeout(resolve, ms)); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment