of course.
here it is. i get a constant 4.5 speed increase factor going float. :o
public class FilteringTest
{
public static void main(String args[])
{
FilteringTest ft=new FilteringTest();
ft.startInt();
ft.startFloat();
}
static final int nbPixels = 1024*1024; // change to set a new image size
static final int loopCount = 500; // change to set a different image filtering count. Verification of the pixel will not match text printed. (i'm lazy)
static int t;
static float tf;
void startInt()
{
long debut;
long fin;
int loop=0, imgloop;
int r=0,g=0,b=0,a=0,pixel=0;
debut=System.currentTimeMillis();
int array[]=new int[nbPixels];
fin=System.currentTimeMillis();
System.out.println("init time:"+(fin-debut)+" ms");
imgloop=0;
for (;imgloop<nbPixels; imgloop++)
{
array[imgloop]=0xffffffff;
}
System.out.println("test1: int pixels filtering");
debut=System.currentTimeMillis();
for (;loop<loopCount; loop++)
{
imgloop=0;
for (;imgloop<nbPixels; imgloop++)
{
pixel=array[imgloop];
a=pixel>>>24;
r=(pixel>>>16)&0x000000ff;
g=(pixel>>>8)&0x000000ff;
b=pixel&0x000000ff;
t=((r+g+b)/3)-1; // performing a basic non weighted b&w. (-1 is to decrease the result, so rendering can be verified.)
array[imgloop]=(t<<24)+(t<<16)+(t<<8)+t;
}
}
fin=System.currentTimeMillis();
long test1=(fin-debut);
System.out.println("Elapsed time: "+test1+" ms");
int nbpix1=(int) ((nbPixels*loopCount)/((double)test1/1000.f));
System.out.println(nbpix1+" pixels/second, that is "+(((double)nbpix1/(720*576*25))*100)+"% of real time video filtering.");
System.out.println("random pixel result for validity of rendering: 0x"+ Integer.toHexString( array[ (int)(Math.random() * nbPixels) ] ));
System.out.println("result should be:0x0a0a0a0a" +"\n\n");
array=null;
}
void startFloat()
{
long debut;
long fin;
int loop=0, imgloop;
float r=0.f,g=0.f,b=0.f,a=0.f;
debut=System.currentTimeMillis();
float array[]=new float[nbPixels*4];
fin=System.currentTimeMillis();
System.out.println("init time:"+(fin-debut)+" ms");
imgloop=0;
for (;imgloop<nbPixels; imgloop++)
{
array[imgloop]=150000.f;
}
System.out.println("test2: float pixels filtering");
debut=System.currentTimeMillis();
for (;loop<loopCount; loop++)
{
imgloop=0;
for (;imgloop < nbPixels ; imgloop+=4)
{
a=array[imgloop];
r=array[imgloop+1];
g=array[imgloop+2];
b=array[imgloop+3];
tf=((r+g+b)/3.f)-1; // performing a basic non weighted b&w. (-1 is to decrease the result, so validity of rendering can be verified.)
array[imgloop]=tf;
array[imgloop+1]=tf;
array[imgloop+2]=tf;
array[imgloop+3]=tf;
}
}
fin=System.currentTimeMillis();
long test1=(fin-debut);
System.out.println("Elapsed time: "+test1+" ms");
int nbpix1=(int) ((nbPixels*loopCount)/((double)test1/1000.f));
System.out.println(nbpix1+" pixels/second, that is "+(((double)nbpix1/(720*576*25))*100)+"% of real time video filtering.");
System.out.println("random pixel result for validity of rendering:"+ array[ (int)(Math.random() * nbPixels) ] );
System.out.println("result should be:149500" +"\n\n");
array=null;
}
}