StopWatch
特意的百度了下 是“秒表的意思”
废话不多说 直接上代码
public static void main(String[] args) throws InterruptedException {
// 定义一个计数器
StopWatch stopWatch = new StopWatch("统一一组任务耗时");
stopWatch.start("任务一");
int [] arr = {3, 2, 67, 5, 4, 1, 9,232,434,545,6776,879,23,5678,9898,56321,344568,2343};
SelectSort (arr);
System.out.println(JSON.toJSONString(arr));
// 统计任务一耗时
Thread.sleep(1000);
stopWatch.stop();
String result = stopWatch.prettyPrint();
System.err.println(result);
}
//简单选额排序
private static void SelectSort (int [] arr) {
int min, temp, tempIndex; //最小值,交换中间值,每轮换得的最小值索引
for (int i = 0; i < arr.length; i++) {
min = arr [i];
tempIndex = i;
for (int j = i + 1; j < arr.length; j++) { //比较得到最小值和其索引值
if (arr [j] < min) {
min = arr [j];
tempIndex = j;
}
}
//交换
temp = arr [i];
arr [i] = arr [tempIndex];
arr [tempIndex] = temp;
}
}
运行后的效果
StopWatch '统一一组任务耗时': running time (millis) = 1122
-----------------------------------------
ms % Task name
-----------------------------------------
01122 100% 任务一