嗨,我試圖找出一個方法需要執行多長時間。這個looging返回一個負數的浮點數,任何想法爲什麼?謝謝。方法執行的日誌記錄時間
method(){
startTime = System.currentTimeMillis();
.....code to execute
endTime = System.currentTimeMillis();
}
long sampleDur = endTime - startTime;
。
好的,我已經刪除了浮動:)。我仍然對樣本方法有負面影響?我會發布實際的代碼。它基本上通過位圖循環,sample和getRadial是在該循環內調用的方法。
06-15 21:04:26.945:ERROR /過濾器(6424):樣品的方法把-9ms 06-15 21:04:26.945:ERROR /過濾器(6424):getRadialX了0毫秒 06-15 21 :04:26.945:ERROR /過濾器(6424):循環了40144ms
long getRadXStart = 0;
long getRadXEnd = 0;
long startSample = 0;
long endSample = 0;
long startLoop = System.currentTimeMillis();
for(int j=0;j<dst.getHeight();j++){
for(int i=0;i<dst.getWidth();i++){
origPixel= input.getPixel(i,j);
getRadXStart = System.currentTimeMillis();
float x = getRadialX((float)j,(float)i,centerX,centerY,k);
getRadXEnd= System.currentTimeMillis();
float y = getRadialY((float)j,(float)i,centerX,centerY,k);
sampleImage(input,x,y);
int color = ((s[1]&0x0ff)<<16)|((s[2]&0x0ff)<<8)|(s[3]&0x0ff);
// System.out.print(i+" "+j+" \\");
if(Math.sqrt(Math.pow(i - centerX, 2) + (Math.pow(j - centerY, 2))) <= 150){
dst.setPixel(i, j, color);
}else{
dst.setPixel(i,j,origPixel);
}
}
}
long endLoop = System.currentTimeMillis();
long loopDuration = endLoop - startLoop;
long radXDuration = getRadXEnd - getRadXStart;
long sampleDur = endSample - startSample;
Log.e(TAG, "sample method took "+sampleDur+"ms");
Log.e(TAG, "getRadialX took "+radXDuration+"ms");
Log.e(TAG, "loop took "+loopDuration+"ms");
// Log.e(TAG, "***********filter.barrel() looped through bm about to return dst bm");
return dst;
}
void sampleImage(Bitmap arr, float idx0, float idx1)
{
startSample = System.currentTimeMillis();
s = new int [4];
if(idx0<0 || idx1<0 || idx0>(arr.getHeight()-1) || idx1>(arr.getWidth()-1)){
s[0]=0;
s[1]=0;
s[2]=0;
s[3]=0;
return;
}
float idx0_fl=(float) Math.floor(idx0);
float idx0_cl=(float) Math.ceil(idx0);
float idx1_fl=(float) Math.floor(idx1);
float idx1_cl=(float) Math.ceil(idx1);
int [] s1 = getARGB(arr,(int)idx0_fl,(int)idx1_fl);
int [] s2 = getARGB(arr,(int)idx0_fl,(int)idx1_cl);
int [] s3 = getARGB(arr,(int)idx0_cl,(int)idx1_cl);
int [] s4 = getARGB(arr,(int)idx0_cl,(int)idx1_fl);
float x = idx0 - idx0_fl;
float y = idx1 - idx1_fl;
s[0]= (int) (s1[0]*(1-x)*(1-y) + s2[0]*(1-x)*y + s3[0]*x*y + s4[0]*x*(1-y));
s[1]= (int) (s1[1]*(1-x)*(1-y) + s2[1]*(1-x)*y + s3[1]*x*y + s4[1]*x*(1-y));
s[2]= (int) (s1[2]*(1-x)*(1-y) + s2[2]*(1-x)*y + s3[2]*x*y + s4[2]*x*(1-y));
s[3]= (int) (s1[3]*(1-x)*(1-y) + s2[3]*(1-x)*y + s3[3]*x*y + s4[3]*x*(1-y));
endSample = System.currentTimeMillis();
}
Log.e(TAG, "sample method took "+(float)sampleDur+"seconds");
你爲什麼要轉換爲浮動?它很長。 – Stuck 2011-06-15 19:47:35