Created
          August 26, 2020 06:31 
        
      - 
      
- 
        Save jasonsturges/6b15e39c8e0049a3f96bd9b4a3a9180e to your computer and use it in GitHub Desktop. 
    Benchmarking JavaScript - Tuning execution time
  
        
  
    
      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(); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment