Advertisement
DigitalMag

the simplest perfomance benchmark (node)

Oct 7th, 2020 (edited)
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const performance = require('perf_hooks').performance;
  2.  
  3. function checkout(n){
  4.    
  5.     var sum = 0;
  6.     for(var i=0;i<n;i++){
  7.         sum+=1;
  8.     }  
  9.     return sum;
  10. }
  11.  
  12. function apply(n){
  13.     var time = performance.now();
  14.  
  15.     console.log(checkout(n));
  16.  
  17.     time = performance.now()- time;
  18.     console.log('execution time = ', time);
  19.    
  20. }
  21.  
  22. for (let index = 0; index < 5; index++) {
  23.     apply(10**6);
  24. }
  25.  
  26. // => ~14-1 ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement