|
|
|
|
|
by d2mw
2524 days ago
|
|
I'm no Java ninja, but a few things jump out of https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/19fb8f93c... : - at least one heap allocation for every line. After it finds the EOL it first uses 'new String' followed by '.toString() - the C++ version will almost certainly be backing on to memchr() behind the scenes, which will be using SIMD instructions where it makes sense (e.g. large enough scan size, probably true in this case). the Java version is a manual bytewise-coded loop. - the C++ version is reusing its output buffer, no reallocations assuming the same string length or less No idea about encodings in Java, maybe that is playing a role too |
|
As a result std::string was disgustingly slow compared to C code.