本文主要是介绍java -- while循环拆分性能测试程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
public class SimpleTest {
// 包含打印操作
//100000 658 1061 1.6
//1000000 5576 5073 0.9// 纯加操作
//100000 4 6 1-1.5
//100000 15 27 1.8
//10000000 33 66 2.0
public static void main(String[] args) {final int N = 10000000;List<Integer> list = new ArrayList<>();for (int i = 0; i < N; i++) {list.add(i);}TimeWatcher watcher = new TimeWatcher();long sum1 = 0;long sum11 = 0;Iterator<Integer> it = list.iterator();while (it.hasNext()) {int i = it.next();sum11 += i;sum1 += i;}long firstInterval = watcher.interval();long sum2 = 0;long sum22 = 0;Iterator<Integer> it2 = list.iterator();while (it2.hasNext()) {int i = it2.next();sum2 += i;}it2 = list.iterator();while (it2.hasNext()) {int i = it2.next();sum22 += i;}long secondInterval = watcher.interval();System.out.println(firstInterval);System.out.println(secondInterval);System.out.println(1.0 * secondInterval / firstInterval);}
}
这篇关于java -- while循环拆分性能测试程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!