>>>>> "Joseph" == Joseph H Buehler <[EMAIL PROTECTED]> writes:
> I am trying to do some simple image processing with Java, and finding
> the performance to be not exactly stellar. My code was originally
> written in C++ using Motif, and that version runs circles around the
> Java version.
The java.util.* classes are tuned for safety (particularly in a
multi-threaded environment) rather than performance. Ok, maybe
"tuned" is too strong a word. ;-)
I'm on a very similar setup to yours (ppro200, RH5.1+kernel2.2.1,
jdk117, tya12v3) - not sure why my base time is significantly faster.
Your code (as written):
TYA 1.2v3 (for J117 / Linux). Copyright (c) 1997,98,99 The TYA Team
Contact The TYA Team via Albrecht Kleine <[EMAIL PROTECTED]>
seconds: 20
iterations/second: 94545.0
Now, using a Tuned bitset which doesn't do bounds checking, an extra
static method call and a synchronize per set():
TYA 1.2v3 (for J117 / Linux). Copyright (c) 1997,98,99 The TYA Team
Contact The TYA Team via Albrecht Kleine <[EMAIL PROTECTED]>
seconds: 7
iterations/second: 266567.0
True, we've now lost expandability, error checking and simultaneous
access, but if you don't need those facilities, you might as well not
pay for 'em.
A little experimentation shows that by far the largest factor in this
code is the synchronize in the BitSet.set() implementation.
Allegedly, HotSpot (and perhaps other vms/jits) should make syncs
significantly faster. Meanwhile, if you really need fast java, you
should be careful choosing which classes you use off the shelf and
which you write yourself.
Cheers,
-mik
> I wrote the following as a simple test to make sure that I do not have
> something wrong with my Java setup:
> package test;
> import java.util.*;
> class testmain
> {
> public static void main(String argv[]) {
> long start = System.currentTimeMillis();
> int iterations = 10 * 1024 * 1024;
> BitSet b = new BitSet();
> for (int i=0; i<iterations; ++i) {
> b.set(i);
> }
> long stop = System.currentTimeMillis();
> float rate = iterations * 1000 / (stop - start);
> System.out.println("seconds: " + ((stop - start) / 1000));
> System.out.println("iterations/second: " + rate);
> }
> }
> When I run this on my PPro 200 Redhat 5.1 box, I see the following:
> CLASSPATH="testmain:$CLASSPATH" java test.testmain
> TYA 1.2v3 (for J117 / Linux). Copyright (c) 1997,98,99 The TYA Team
> Contact The TYA Team via Albrecht Kleine <[EMAIL PROTECTED]>
> seconds: 27
> iterations/second: 67851.0
--
Michael Thome ([EMAIL PROTECTED])