-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopTest.java
More file actions
34 lines (27 loc) · 868 Bytes
/
LoopTest.java
File metadata and controls
34 lines (27 loc) · 868 Bytes
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
package com.chen.other;
/**
* Created by chenwj3 on 2017/2/20.
*/
public class LoopTest {
public static void main(String args[]) {
complexLoop();
}
public static void complexLoop() {
long before = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 100000000; j++) {
new String();
}
}
long after = System.currentTimeMillis();
System.out.println("小嵌大循环耗时:" + (after - before) + "ms");
long before2 = System.currentTimeMillis();
for (int i = 0; i < 100000000; i++) {
for (int j = 0; j < 10; j++) {
new String();
}
}
long after2 = System.currentTimeMillis();
System.out.println("大嵌小循环耗时:" + (after2 - before2) + "ms");
}
}