Created
          June 2, 2016 19:05 
        
      - 
      
- 
        Save sagivo/82a780702381a52e736f59a2f9d7cd63 to your computer and use it in GitHub Desktop. 
    benchmark of vs in
  
        
  
    
      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
    
  
  
    
  | 'use strict'; | |
| const timer = function(name) { | |
| var start = new Date(); | |
| return { | |
| stop: function() { | |
| var end = new Date(); | |
| var time = end.getTime() - start.getTime(); | |
| console.log('Timer:', name, 'finished in', time, 'ms'); | |
| } | |
| } | |
| }; | |
| var a = []; | |
| for (var i = 0; i < 1000000; i++) { | |
| a.push(i); | |
| } | |
| let foo = 0; | |
| var t = timer('using of'); | |
| for (const i of a) foo = i; | |
| t.stop(); | |
| var t = timer('using in'); | |
| for (const i in a) foo = i; | |
| t.stop(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Timer: using of finished in 61 ms
Timer: using in finished in 220 ms