There is a piece of code that loads lines from a file into a collection with unique values.
var WORDS = new Set() let file = fs.readFileSync('file.txt') // 1 500 000+ строк // Прошло ~10 мс let text = iconv.decode(file, 'windows-1251') // Прошло ~100 мс let list = text.split('\n') // Прошло ~500 мс let i = 0 while (list[i] != null) { // Быстрее, чем "WORDS = new Set(list)" WORDS.add(list[i++]) } // Прошло ~1100 мс The thickest parts of the code are splitting into cells and iteration. Is it possible to optimize this?
UPD:
Everything is done in order to quickly look for the value in the collection
WORDS.has('string') // true или false So, if there are other ways to store and search for unique values, I’m in favor