6 ms·
Regarding the C++ version: instead of copying data to a vector and then sorting the vector, it might be more profitable to use std::multimap<size_t, string>. Th
by wmu 6y ago
Regarding the C++ version: instead of copying data to a vector and then sorting the vector, it might be more profitable to use std::multimap<size_t, string>. This is a sorted container (likely rb-tree based) that handles duplicated keys.
Also, as somebody else mentioned, iostreams are slow. Even simple reading of file can be several times slower than plain C (http://0x80.pl/notesen/2019-01-07-cpp-read-file.html http://0x80.pl/notesen/2019-01-07-cpp-read-file.html).
- jpcooper 6y agoMaybe due to stdio synchronisation? This can be turned off. https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdi...
- usefulcat 6y agoHe did that: "This line makes it run almost twice as fast: ios::sync_with_stdio(false);"