This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Help with performance issues.


Hello,
	As requested, here is a some actual code.  On our test machine
(i686, Mandrake linux 8) using the attached make script to compile the gcj
and jdk versions results in the gcj version consistantly running around
10-20 seconds slower than the jdk version.
Once again, thanks for all the help on this.
Best wishes,
		William Bland.
javac myclass.java

CLASSPATH=

gcj -static -O3 --no-bounds-checking -funroll-loops -finline-functions -fkeep-inline-functions -march=i686 -malign-double --main=myclass -o myclass myclass.java
// This runs slower with gcj than with jdk1.3
// Obviously some optimisations are possible (e.g. all myclass objects in this
// test have data_offset=0) but I have left them in here because they may actually
// be causing the performance difference, and (of course) in the real code we don't
// have data_offset==0 for every myclass object.
// Also we don't need to do array[index % array.length] in this example, but we
// do need it in the production code.  Same for checking list.id != -1.

import java.io.*;

public class myclass
{
	myclass next;
	int id;
	int error;
	int data[];
	int data_offset;

	static final int abs( int x )
	{
		if( (0x80000000 & x) == 0 )
		  return x;
		else
		  return -x;
	}
	
	public static final void main( String[] args )
	{
		int[] empty = new int[1000];
		int[] full = new int[1000];
		int[] up = new int[1000];
		int[] down = new int[1000];
		for( int i=0; i<1000; i++ )
		{
			full[i] = i;
			up[i] = i+10;
			down[i] = i-10;
		}
		myclass list = null;
		myclass fullc = new myclass( full );
		fullc.next = list;
		list = fullc;
		for( int i=0; i<100000; i++ )
		{
			myclass tmp = new myclass( empty );
			tmp.next = list;
			list = tmp;
		}
		long time1 = System.currentTimeMillis();
		for( int i=0; i<5000; i++ )
		{
//			System.out.println( "i = " + i + ".  Elapsed time = " + (System.currentTimeMillis()-time1) );
			find( list, full, up, down );
		}
		if( find( list, full, up, down ) == fullc )
		  System.out.println( "Everything worked" );
		else
		  System.out.println( "Something went wrong!" );
		long time2 = System.currentTimeMillis();
		System.out.println( "Run time = " + (time2 - time1) + " ms" );
	}
	
	public myclass( int[] thedata )
	{
		data = thedata;
	}
	
	public static final myclass find( myclass list, int[] input, int[] input_up, int[] input_down )
	{
		int end = 1000;
		int i, j;
		while( list != null )
		{
			if( list.id != -1 )
			{
				for( i=end-1, j=end-1; i > 0
				     && list.data[list.data_offset+j] <= input_up[i%input_up.length]
				     && list.data[list.data_offset+j] >= input_down[i%input_down.length]
				     && list.error <= 100000; i--, j-- )
					list.error += abs( list.data[list.data_offset+j] - input[i%input.length] );
				if( i == 0 )
					return( list );
			}
			list = list.next;
		}
		return( null );
	}
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]