This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
RE: Different results of java and C verion of same program ?
- From: Andrew Haley <aph at redhat dot com>
- To: David Balazic <david dot balazic at hermes dot si>
- Cc: Mark Wielaard <mark at klomp dot org>, java at gcc dot gnu dot org
- Date: Fri, 10 Mar 2006 15:32:27 +0000
- Subject: RE: Different results of java and C verion of same program ?
- References: <0C3E356FC19C134F8061D1A69D1F92D9012FFB04@piramida.hermes.si>
David Balazic writes:
> From: Mark Wielaard [mailto:mark@klomp.org]
> >
> > On Wed, 2006-03-08 at 11:06 +0100, David Bala¾ic wrote:
> > > The main part of the program is a double loop, comparing
> > each element of
> > > a Vector
> > > with all other elements of the Vector (except itself).
> > >
> > > Any ideas for speedup ?
> >
> > A Vector is synchronized on all operations. If you don't need this try
> > using an ArrayList and loop over it with an Iterator. gcj might not
> > optimize away the synchronized accesses on Vector.
>
> I use a Vector, becasue I fill it with data read from file and I don't know
> beforehand the amount of data.
> Should copy the data over to new ArrayList, after the Vector is done ?
No. Simply replace all cases of ArrayList in your code with Vector.
> Unrelated to gcj :
> I implemented a better algorithm, which is O(n) instead of O(n*n)
> and compared Sun JIT to a C++ port. The C++ version is twice slower :-)
Err, something weird is happening.
Andrew.