package com.hknaruto; import java.util.Random; /** * Created by yeqiang on 4/24/18. */ public class IntegerPerformanceTest { public static void main(String[] args) { long start, end; int rand = new Random().nextInt(); start = System.nanoTime(); int c = 0; for (Integer i = 0; i < 100000000; i++) { c += rand + i; } end = System.nanoTime(); System.out.println(c); System.out.println(end - start); start = System.nanoTime(); c = 0; for (int i = 0; i < 100000000; i++) { c += rand + i; } end = System.nanoTime(); System.out.println(c); System.out.println(end - start); } }
输出
-1508346240 396963018 -1508346240 34686095