1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public class Test {
public static void main(String[] args) {
a();
b();
c();
d();
}
private static void a() {
long b = 0;
long start = System.nanoTime();
for (int a = 0; a < 100; a++) {
b += 1;
}
long duree = System.nanoTime() - start;
System.out.println("long = " + duree);
}
private static void b() {
byte b = 0;
long start = System.nanoTime();
for (int a = 0; a < 100; a++) {
b += 1;
}
long duree = System.nanoTime() - start;
System.out.println("byte = " + duree);
}
private static void c() {
int b = 0;
long start = System.nanoTime();
for (int a = 0; a < 100; a++) {
b += 1;
}
long duree = System.nanoTime() - start;
System.out.println("int = " + duree);
}
private static void d() {
Integer b = new Integer(0);
long start = System.nanoTime();
for (int a = 0; a < 100; a++) {
b += 1;
}
long duree = System.nanoTime() - start;
System.out.println("Integer = " + duree);
}
} |
Partager