Optimizing Java method

P

Patricia Shanahan

Benjamin White wrote:
....
My first goal is to just learn to write fast code in theory, a good
algorithm. The package may run on many different JVMs and hardware. I
would want to code for one type of environment and make to others suffer.
....

If you want to learn to write fast code, you may find it helpful to
start with a good process. If I am going to hand tune some code, I start
by making sure I have:

1. A unit test. The unit test may simply compare the implementation
being tested to the existing implementation, but must cover a lot of
edge cases.

2. A performance test. The performance test, or tests, cover only common
cases, but do enough of them for meaningful timing.

Without those, it is hard to know whether the tuned version is, in fact,
a faster version of the same function. It may be a slower implementation
of the same function, or even not be an implementation of that function
at all.

Patricia
 
I

Ingo R. Homann

Hi,

Benjamin said:
Thanks for testing. Someone was complaining that the routine was slow.
It may be called 10 to 100 million times for a large batch of data.
So every little bit of improvement will help.

Thanks everyone for all the good suggestions. I learned alot. I will
try many of the suggestions and test. I may have to call the program
multiple times in a loop to see the differences. If anyone is
interested I will post the results.

[X] Interested! (Because measuring is most important on optimization.)

Ciao,
Ingo
 
B

bugbear

Patricia said:
1. A unit test. The unit test may simply compare the implementation
being tested to the existing implementation, but must cover a lot of
edge cases.

I sometimes use a blatently slow, but "correct by inspection"
implementation for a reference.

BugBear
 
B

bugbear

Benjamin said:
Everyone, thanks for all the good suggestions. I am making changes and
testing. Some have made good improvement. Calling the Java method
100,000 times, the duration dropped from 94 to 31 milliseconds.

You also said...
"It may be called 10 to 100 million times for a large batch of data."

which means for a "large batch of data" your OLD code
would have spent 94 seconds (*) in stringToPack().

How long does the complete processing
for a "large batch of data" take?

BugBear

(*) 100000000 / 100000 * 94 / 1000
 

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

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,329
Latest member
InezZ76898

Latest Threads

Top