writeLong() performance

C

Chris

Hi all,

I'm rewriting an application that produces lots of large integers. My
first version uses BigIntegers and writes them as decimal string to an
output file. To improve the performance, I implemented a second version
which uses long datatypes instead of BigIntegers, and
RandomAccessFile's writeLong() function. But instead of improving the
performance, this second version is much slower than the first version.

What might be the reason for this unexpected behaviour?

Thanks for any hints,
Chris

PS: I'm using "java 1.4.2" from SUN.
 
R

Roedy Green

But instead of improving the
performance, this second version is much slower than the first version.

Conversion to and from decimal String will be faster with BigDecimal,
but I would expect everything else to be faster. Did you measure which
method was accounting for the difference?
 
T

Thomas Weidenfeller

Chris said:
But instead of improving the
performance, this second version is much slower than the first version.

What might be the reason for this unexpected behaviour?

Get a profiler tool and measure where you have the performance problems.

/Thomas
 
T

Thomas Hawtin

Chris said:
I'm rewriting an application that produces lots of large integers. My
first version uses BigIntegers and writes them as decimal string to an
output file. To improve the performance, I implemented a second version
which uses long datatypes instead of BigIntegers, and
RandomAccessFile's writeLong() function. But instead of improving the
performance, this second version is much slower than the first version.

How many digits in your numbers? Discs tend to be slower than
processors. If the second version produces a larger file, then it
shouldn't be too surprising that it can be slower.

On the other hand, now that I look at RandomAccessFile it appears
hideously inefficient for this sort of operation. writeLong involves
eight native method calls. I suggest only using bulk operations on
RandomAccessFile, if performance is a concern.

Tom Hawtin
 

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,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top