publicclassTestIfElse { publicstaticvoidmain(String[] args) { long startTime; long durationNanoSecond1; long durationNanoSecond2; intiteration_max=100000000; booleanflag=true;
doubleratio= (double)durationNanoSecond1 / (double)durationNanoSecond2; System.out.printf("If / Ternary Time Ratio %f: in %d times iteration\n", ratio, iteration_num); } } }
运行结果:
1 2 3 4 5 6 7 8
If / Ternary Time Ratio 1.166429: in 10 times iteration If / Ternary Time Ratio 1.166845: in 100 times iteration If / Ternary Time Ratio 0.978240: in 1000 times iteration If / Ternary Time Ratio 1.005771: in 10000 times iteration If / Ternary Time Ratio 0.666807: in 100000 times iteration If / Ternary Time Ratio 0.602651: in 1000000 times iteration If / Ternary Time Ratio 2.331681: in 10000000 times iteration If / Ternary Time Ratio 1.138700: in 100000000 times iteration