计算程序运行时间的方法

第一种
long startTime = System.currentTimeMillis();
bubbleSort(arr);
long endTime = System.currentTimeMillis();
System.out.println(endTime-startTime);

第二种
Date date1 = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String date1Str = simpleDateFormat.format(date1);
sout("程序运行前的时间是:“+date1Str);

bubbleSort(arr);

Date date2 = new Date();
String date2Str = simpleDateFormat.format(date2);
sout("程序运行前的时间是:“+date2Str);

你可能感兴趣的:(Thoughts)