FileDocCategorySizeDatePackage
ConvertTest.javaAPI DocExample26169Wed Apr 05 10:37:48 BST 2000tuning.loop

ConvertTest

public class ConvertTest extends Object

Fields Summary
public static final char[]
MAP1
public static final char[]
MAP2
public static final char[]
MAP3
public static final int[]
MAP4
public static final int[]
MAP5
public static int
REPEAT
Constructors Summary
Methods Summary
public static intconvert(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

	              
		 
	
		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < byteEnd;)
		{
			if(charOff >= charEnd)
				throw new Exception();
			int i1 = input[byteOff++];
			if(i1 >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
		}

		return charOff - charStart;
	
public static intconvert1(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < byteEnd;)
		{
			if(charOff >= charEnd)
				throw new Exception();
			int i1 = input[byteOff++];
			if(i1 >= 0)
				output[charOff++] = MAP1[i1];
			else
				output[charOff++] = (char)(256 + i1);
		}

		return charOff - charStart;
	
public static intconvert10(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int max = byteEnd;
		boolean throwException = false;
		if ( byteEnd-byteStart > charEnd-charStart )
		{
			max = byteStart+(charEnd-charStart);
			throwException = true;
		}

		int charOff = charStart;
		if (max-byteStart > 10)
		{
			max -= 10;
			int byteOff = byteStart;
			for(; byteOff < max;)
			{
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
			}

			max += 10;
			for(; byteOff < max;)
			{
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
			}
		}
		else
		{
			for(int byteOff = byteStart; byteOff < max;)
			{
				output[charOff++] = (char) MAP5[input[byteOff++]+128];
			}
		}
		if(throwException)
			throw new Exception();

		return charOff - charStart;
	
public static intconvert2(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < byteEnd;)
		{
			if(charOff >= charEnd)
				throw new Exception();
			int i1 = input[byteOff++];
			if(i1 >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = MAP2[128 + i1];
		}

		return charOff - charStart;
	
public static intconvert3(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < byteEnd;)
		{
			if(charOff >= charEnd)
				throw new Exception();
			int i1 = input[byteOff++];
			output[charOff++] = MAP3[128 + i1];
		}

		return charOff - charStart;
	
public static intconvert4(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < byteEnd;)
		{
			if(charOff >= charEnd)
				throw new Exception();
			output[charOff++] = MAP3[128 + input[byteOff++]];
		}

		return charOff - charStart;
	
public static intconvert5(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < byteEnd;)
		{
			if(charOff >= charEnd)
				throw new Exception();
			int i1 = input[byteOff++];
			output[charOff++] = (char) (i1 + MAP4[128 + i1]);
		}

		return charOff - charStart;
	
public static intconvert6(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < byteEnd;)
		{
			if(charOff >= charEnd)
				throw new Exception();
			output[charOff++] = (char) MAP5[128 + input[byteOff++]];
		}

		return charOff - charStart;
	
public static intconvert7(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int max = byteEnd;
		boolean throwException = false;
		if ( byteEnd-byteStart > charEnd-charStart )
		{
			max = byteStart+(charEnd-charStart);
			throwException = true;
		}

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < max;)
		{
			output[charOff++] = MAP3[input[byteOff++]+128];
		}
		if(throwException)
			throw new Exception();

		return charOff - charStart;
	
public static intconvert8(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int max = byteEnd;
		boolean throwException = false;
		if ( byteEnd-byteStart > charEnd-charStart )
		{
			max = byteStart+(charEnd-charStart);
			throwException = true;
		}

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < max;)
		{
			output[charOff++] = (char) MAP5[input[byteOff++]+128];
		}
		if(throwException)
			throw new Exception();

		return charOff - charStart;
	
public static intconvert9(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int max = byteEnd;
		boolean throwException = false;
		if ( byteEnd-byteStart > charEnd-charStart )
		{
			max = byteStart+(charEnd-charStart);
			throwException = true;
		}

		int charOff = charStart;
		if (max-byteStart > 10)
		{
			max -= 10;
			int byteOff = byteStart;
			for(; byteOff < max;)
			{
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
				output[charOff++] = MAP3[input[byteOff++]+128];
			}

			max += 10;
			for(; byteOff < max;)
			{
				output[charOff++] = MAP3[input[byteOff++]+128];
			}
		}
		else
		{
			for(int byteOff = byteStart; byteOff < max;)
			{
				output[charOff++] = MAP3[input[byteOff++]+128];
			}
		}
		if(throwException)
			throw new Exception();

		return charOff - charStart;
	
public static intconverta(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int max = byteEnd;
		boolean throwException = false;
		if ( byteEnd-byteStart > charEnd-charStart )
		{
			max = byteStart+(charEnd-charStart);
			throwException = true;
		}

		int charOff = charStart;
		for(int byteOff = byteStart; byteOff < max;)
		{
			int i1 = input[byteOff++];
			if(i1 >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
		}
		if(throwException)
			throw new Exception();

		return charOff - charStart;

	
public static intconvertb(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int max = byteEnd;
		boolean throwException = false;
		if ( byteEnd-byteStart > charEnd-charStart )
		{
			max = byteStart+(charEnd-charStart);
			throwException = true;
		}

		int charOff = charStart;
		int i1;
		for(int byteOff = byteStart; byteOff < max;)
		{
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
		}
		if(throwException)
			throw new Exception();

		return charOff - charStart;

	
public static intconvertc(byte[] input, int byteStart, int byteEnd, char[] output, int charStart, int charEnd)

		int max = byteEnd;
		boolean throwException = false;
		if ( byteEnd-byteStart > charEnd-charStart )
		{
			max = byteStart+(charEnd-charStart);
			throwException = true;
		}

		int charOff = charStart;
		int i1;
		if (max-byteStart > 10)
		{
			max -= 10;
			int byteOff = byteStart;
			for(; byteOff < max;)
			{
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			}

			max += 10;
			for(; byteOff < max;)
			{
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			}
		}
		else
		{
			for(int byteOff = byteStart; byteOff < max;)
			{
			if( (i1 = input[byteOff++]) >= 0)
				output[charOff++] = (char)i1;
			else
				output[charOff++] = (char)(256 + i1);
			}
		}

		if(throwException)
			throw new Exception();

		return charOff - charStart;

	
public static voidmain(java.lang.String[] args)

          maintest(args);
//          maintest(args);
        
public static voidmaintest(java.lang.String[] args)

          if (args.length == 1)
            REPEAT = Integer.parseInt(args[0]);
		try
		{
			byte[] b = {
				1,2,55,99,-35,-64,-127,44,111,127,
				10,20,5,9,-5,-6,-27,4,11,17,
				110,112,-55,-99,35,64,127,-44,-111,27,
				100,62,54,109,-115,-96,-17,33,11,7,
				18,28,58,98,-38,-86,-87,48,108,28,
				1,2,55,99,-35,-64,-127,44,111,127,
				10,20,5,9,-5,-6,-27,4,11,17,
				110,112,-55,-99,35,64,127,-44,-111,27,
				100,62,54,109,-115,-96,-17,33,11,7,
				18,28,58,98,-38,-86,-87,48,108,28,
			};
			char[] c = new char[100];

			long time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				converta(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("converta took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convertb(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convertb took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convertc(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convertc took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert1(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert1 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert2(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert2 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert3(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert3 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert4(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert4 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert5(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert5 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert6(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert6 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert7(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert7 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert8(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert8 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert9(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert9 took " + time);

			time = System.currentTimeMillis();
			for (int i = REPEAT; i > 0 ; i--)
				convert10(b,0,b.length,c,0,b.length);
			time = System.currentTimeMillis() - time;
			System.out.println("convert10 took " + time);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}