I've written some code and it is running much slower than I would like it
to. I'm from the C school of optimization which says that you write the
code the best way you can and then when you get done you run it through a
profiler to get the optimization done. This has always served me well in
the C world. To paraphrase Knuth, "Premature optimization is the root of
all evil."
So this has been the philosophy I've used in Java as well, but now it just
doesn't seem to be serving me well. The profiler isn't showing any really
hot spots that need work (which was quite surprising) and it shows only a
very small amount of time being used in garbage collection. Yet the code
is much, much slower than other implementations in C or C++.
So what is the best procedure for getting performance from a Java
application?
Thanks.
BTW, I'm using the profiler that comes with NetBeans.

Signature
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>
Arne Vajhøj - 05 Dec 2007 02:13 GMT
> I've written some code and it is running much slower than I would like it
> to. I'm from the C school of optimization which says that you write the
[quoted text clipped - 11 lines]
> So what is the best procedure for getting performance from a Java
> application?
Your procedure looks fine.
Even though there are no hotspots, then it must obviously spend
somewhere.
Try look at the code.
Possible post some code snippts for comments and suggestions
for improvement.
Arne
Zig - 05 Dec 2007 02:46 GMT
> I've written some code and it is running much slower than I would like it
> to. I'm from the C school of optimization which says that you write the
[quoted text clipped - 17 lines]
>
> BTW, I'm using the profiler that comes with NetBeans.
Not sure about the NetBeans profiler, but time your app without the
profiler, and again with the profiler. If those figures don't look
similar, you may have too much instrumentation turned on in the profiler.
GC time is usually pretty small until the heap utilization starts getting
high. But, some profilers will break "allocation time" seperately from
"runnable time" (likewise for I/O wait, wait, blocked). So, if your
algorithm takes 15 seconds, and the time spent in java.lang.Thread.run()
(or MyClass.main(String[]) ) is less than 15 seconds, then your profiler
is hiding something.
HTH,
-Zig
bugbear - 05 Dec 2007 09:39 GMT
> I've written some code and it is running much slower than I would like it
> to. I'm from the C school of optimization which says that you write the
[quoted text clipped - 11 lines]
> So what is the best procedure for getting performance from a Java
> application?
Hmm. My "guess" (on the minimal information you provide) is
that something "global" to your application is slow.
This could either be "the JVM" (i.e. language overhead)
or the "core" datastructure. If this is accessed from
every part of your code, you would get the results
you describe.
Without more detail, I can't say more.
Oh, except possibly, concentrate on "big O" optimisations
first, but I infer that you know that.
BugBear
Mark Space - 05 Dec 2007 17:14 GMT
> BTW, I'm using the profiler that comes with NetBeans.
If you post up what the profiler says (maybe a snapshop after running
one "slow" algorithm) folks can take a poke at it. I'm always
interested in debuggin/speed techniques.