He implemented the algorithm, for both iterative and recursive style, with and without Java 5 language features (e.g. for-each loop). I was struck by the fact that in both cases the implementation using Java 5 language features was significantly slower than using the "old" syntax.
On the other hand, it is also clear that it is easy to inadvertently "give away" performance by, for example, improving readability using Java 5 for-loop iteration. Elegant recursion uses over 1MB of heap space and runs almost as slowly as the fast iterative solution. The elegant iterative solution uses 160% of the fast solution's time, and uses roughly 40 times more heap space.
So I'm asking myself, when it comes to Java 5 language features like the for-each loop or autoboxing/unboxing is it really readability over performance?
0 comments:
Post a Comment