Advertisement
pexea12

Benchmark obj

Jul 2nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const faker = require('faker')
  2.  
  3. const obj = {}
  4.  
  5. for (let i = 0; i < 1000; ++i) {
  6.     obj[faker.name.findName()] = faker.name.jobTitle()
  7. }
  8.  
  9. const list = Object.keys(obj)
  10. console.log('Keys', list.length)
  11.  
  12.  
  13. function test() {
  14.     let count = 0
  15.     console.time('2')
  16.     list.forEach(key => {
  17.         if (obj[key]) ++count
  18.     })
  19.     console.timeEnd('2')
  20.    
  21.     console.time('1')
  22.     list.forEach(key => {
  23.         if (key in obj) ++count
  24.     })
  25.     console.timeEnd('1')
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement