Speed

  • Thread starter Kenneth P. Turvey
  • Start date
K

Kenneth P. Turvey

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.
 
A

Arne Vajhøj

Kenneth said:
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?

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
 
Z

Zig

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.

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
 
B

bugbear

Kenneth said:
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?

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
 
M

Mark Space

Kenneth said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top