Hacker News new | ask | show | jobs
by wmu 1917 days 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).

1 comments

Maybe due to stdio synchronisation? This can be turned off.

https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdi...

He did that:

    "This line makes it run almost twice as fast:
    ios::sync_with_stdio(false);"