5 ms·
Just sounds like a mis-use of Java. Java is slower than C++, but it's a fairly small difference, ie. between 1x and 3x the speed. So if the cpp code did the wor
by RyanZAG 13y ago
Just sounds like a mis-use of Java. Java is slower than C++, but it's a fairly small difference, ie. between 1x and 3x the speed. So if the cpp code did the work in a second, the Java version should have taken at most 3 seconds.
The real reason for the difference is that the rewrite into C++ used all of the domain knowledge he had acquired in writing the Java version. If he has made a Ruby version next, it would likely have been similarly efficient (maybe 5 secs? Who knows).
It's a key problem in these kind of anecdotes: a rewrite will nearly always be more efficient as it has more knowledge to work with during the architecture phase of the project.
- raphinou 13y agoFrom what i know the code was quite simple and even trivial, using existing java libraries as much as possible. The fact is that using corresponding cpp libraries let him get what he needed with much less fuss. I do not know why the java version was so inefficient and used all memory,it might be due to one ofnthe librariez, but this is illustrating an example where cpp was relevant , which was the point of my comment.
- RyanZAG 13y agoAnd if he now rewrote the code in Scala using even better domain knowledge and it ran in 0.1 seconds, would this be proof to you that C++ isn't relevant after all? The point of my comment is that your basis is flawed. The apples to chimpanzees reasoning you are using is not valid.
- raphinou 13y agoI think you missed the point there was no domain knowledge advantage in the second version.