2 chenhuijie666 chenhuijie666 于 2014.08.07 15:29 提问

Java程序测试性能发现执行时间随着循环次数会明显降低

今天用java写了一段算法,主要涉及到treeMap,arraylist的一些操作。

测试流程如下:
algorithm A=new algorithm ();

List testData=new ArrayList();
//循环体内的测试数据集数据量相当,切均不一样。
for(int i=0;i<testData.size();i++)
{
long StartTime=????;//counting time
A.do(testData[i]);
long EndTime=????;//counting time

System.out.printf(EndTime-StartTime);
}

测试的时间如下:

462.15861 298.30576 279.91393 241.7313 239.70447 212.04327 200.1986 165.13594 188.82911 140.16911 188.90014 189.86457 167.04649 175.00024 171.54611 145.32464 215.46838 188.57071 145.68159 164.93144 130.73506 95.79538 90.3491 55.91555 56.26871 94.68095 62.44587 30.38805 19.82224 55.03615 50.84964 25.71251 20.64943 28.68452 24.20626 30.00955 50.45575 42.31878 37.87907 25.53343 59.43558 49.12292 40.52247 31.38126 70.59181 26.32742 41.00252 23.71383 38.23651 47.9771 49.83765 24.44011 43.97743 37.61771 31.24152 21.63171 35.51974 32.0304 34.01891 15.55248 38.32408 35.18586 20.00411 33.87178 36.96588 20.81727 29.10724 18.24478 23.85058 26.70228 24.78474 51.85381 38.02426 33.15712 29.44277 113.47715 27.13189 20.10289 38.55455 37.82762 20.99199 32.82104 16.16431 16.39178 24.1652 32.40064 26.57445 37.97152 34.82924 40.03378 22.32652 17.06048 33.6016 16.3916 40.01449 18.41816 17.29858 26.89135 22.03188 33.82265 21.45578 14.83777 17.52447 20.26137 25.66017 15.95901 17.70299 22.96476 14.10446 13.61584 20.65159 15.5337 16.17566 15.77823 16.08327 18.69095 17.32276 17.59788 19.88928 33.48517 24.78715 27.21507 14.39397 15.62498 16.04994 28.93362 19.30826 21.92023 15.45429 24.61159 20.55774 16.12125 20.05177 23.64231 16.81246 18.59618 15.52088 17.46581 17.04643 17.01347 23.78725 24.42785 13.32318 18.08934 18.41027 32.88003 26.74203 19.33788 21.35031 14.55017 19.22222 28.06258 26.31948 29.1039 22.04832 31.10246 30.73532 18.60818 22.78055 21.88319 23.1518 31.55027 18.12786 12.40602 18.6222 15.44865 20.15852 30.17892 20.13551 56.74019 49.03774 51.31824 37.53917 30.56681 42.194 340.76047 14.85093 25.55332 14.51935 12.56887 11.18639 18.20451 15.06617 13.96165
问题是:程序,刚开始的时候执行时间比较长,到后面,就比较小,比较稳定了,这是什么原因造成的么?每次程序执行都是相互独立的,程序会将涉及到的,数据结构都clear()

1个回答

ZuoQiDeXingFu
ZuoQiDeXingFu   2016.01.13 08:59

我今天也发现了一样的问题 ,没想明白

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!