Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. var WORDS = new Set()
  2.  
  3. let file = fs.readFileSync('file.txt') // 1 500 000+ строк
  4. // Прошло ~10 мс
  5. let text = iconv.decode(file, 'windows-1251')
  6. // Прошло ~100 мс
  7. let list = text.split('n')
  8. // Прошло ~500 мс
  9.  
  10. let i = 0
  11. while (list[i] != null) {
  12. // Быстрее, чем "WORDS = new Set(list)"
  13. WORDS.add(list[i++])
  14. }
  15.  
  16. // Прошло ~1100 мс
  17.  
  18. WORDS.has('string') // true или false
  19.  
  20. let length = list.length;
  21.  
  22. for(var i = 0; i < length; i++){
  23. Worlds.add(list[i]);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement