forked from onlybooks/java-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavaPerf.java
40 lines (34 loc) · 1.42 KB
/
JavaPerf.java
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
package ch04;
public class JavaPerf {
public static void main(String[] args) {
long startTime;
int index;
// int[] 1억 개 삽입
startTime = System.currentTimeMillis();
int[] intElements = new int[100000000];
for (int i = 0; i < 100000000 - 1; i++)
intElements[i] = 1;
intElements[100000000 - 1] = 2;
System.out.printf("int[] 1억 개 삽입: %s밀리초\n", System.currentTimeMillis() - startTime);
// int[] 1억 개 중 찾기
startTime = System.currentTimeMillis();
index = 0;
while (2 != intElements[index])
index++;
System.out.printf("int[] 1억 개 중 찾기: %s밀리초\n", System.currentTimeMillis() - startTime);
// ---
// Integer[] 1억 개 삽입
startTime = System.currentTimeMillis();
Integer[] integerElements = new Integer[100000000];
for (int i = 0; i < 100000000 - 1; i++)
integerElements[i] = 1;
integerElements[100000000 - 1] = 2;
System.out.printf("Integer[] 1억 개 삽입: %s밀리초\n", System.currentTimeMillis() - startTime);
// Integer[] 1억 개 중 찾기
startTime = System.currentTimeMillis();
index = 0;
while (2 != integerElements[index])
index++;
System.out.printf("Integer[] 1억 개 중 찾기: %s밀리초\n", System.currentTimeMillis() - startTime);
}
}