java计算函数执行时间

定义一个起始时间:
long start = System.currentTimeMillis();
//这里是你要执行的程序块。。。。
定义一个结束时间
long end = System.currentTimeMillis();
程序快执行耗时=start-end;

//开始计时
long startTime = System.nanoTime();
            
            
if (convertView == null) {
                convertView 
= mInflater.inflate(R.layout.list_item_icon_text,
                        
null);
            }
            ((ImageView) convertView.findViewById(R.id.icon1)).setImageResource(R.drawable.icon);
            ((TextView) convertView.findViewById(R.id.text1)).setText(mData[position]);
            ((ImageView) convertView.findViewById(R.id.icon2)).setImageResource(R.drawable.icon);
            ((TextView) convertView.findViewById(R.id.text2)).setText(mData[position]);
            
//停止计时
long endTime = System.nanoTime();

//计算耗时
long val = (endTime - startTime) / 1000L;

猜你喜欢

转载自xiaoheichuangtianya.iteye.com/blog/2261470