Java Redux.

There’s something satisfying about conducting a little science, even when you know what the results are going to be.  Well.  I nearly caught a big surprise, but then I remembered I was comparing a debug build to a release one.

Java is slower.  But that’s not to say it doesn’t do very well for a bytecode language.

I copied my large-area terrain tile processor to C++.  Literally in some cases; Java syntax isn’t exactly a world away.  Getting it all running was… frustrating, I guess, but that’s what getting out of the managed world does for you.

I built two versions of the C++ implementation.  One that didn’t care about memory, and one that at least made a token effort about cleaning up as it went along.

Results?

Java: 52s
C++ dirty: 26s
C++ tidy: 33s

The bigger story is memory usage.  Both the Java and “dirty” C++ versions ended with about 220MB allocated.  This suggests the Java garbage collector was sitting around waiting until I either finished what I was doing with the CPU or ran out of memory.

C++ “tidy”, though… 72MB.  Bear in mind it’s got an SRTM DEM in memory throughout; those are 70MB on their own.  That time lost doing one’s own memory management may be worthwhile.

Speaking of time lost… it’s slower to develop in C++.  Doesn’t help that I’m (re)learning as I go along, but it has more gotchas and ways to end up in unpredictable places after a null reference or two.  Also the user community isn’t as good.

This may sound weird but when I was looking to see if other people had solved similar problems, the Java forums where much more helpful.  They tended to follow the 3-post question, answer, explanation of why the answer made sense format.

On a C++ forum it went more: Question, attack on the user for asking the question, nitpick of irrelevant details about how the question was asked, incorrect answer, failure to accept that wrong answer is wrong, further attack on original user… at which point the thread had pretty much died and I’d got an actual book off a bookshelf.  (I know.)

It seems an odd setup but it’s one I’ve seen in the commercial world.  The truth is most of those people posting don’t know the answer either… but they think they should, and this makes them angry at the person who asked.  C++ is a language with a steep learning curve and an involved problem-solving process though; it is hard to know the answers sometimes.  I know I don’t.

(Although I would suggest one of the best questions for narrowing the problem search space is “have you included windows.h?” as it has an interesting habit of redefining stuff you wouldn’t expect.)

Anyway.  Java is slow and uses lots of memory.  But not that slow, and not that unsensible in terms of why it’s using that memory.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s