-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimeFusedLoop.java
More file actions
44 lines (37 loc) · 1.08 KB
/
Copy pathTimeFusedLoop.java
File metadata and controls
44 lines (37 loc) · 1.08 KB
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
public class TimeFusedLoop
{
public static void main(String[] args)
{
long startTime1, startTime2, endTime1, endTime2;
final int REPEAT = 10000;
startTime1 = System.currentTimeMillis();
for(int x = REPEAT ; x >= 0 ; --x)
{
method1(REPEAT);
}
for(int x = REPEAT ; x >= 0 ; --x)
{
method2(REPEAT);
}
endTime1 = System.currentTimeMillis();
System.out.println("Time for two separate loops: " +
(endTime1 - startTime1) + " milliseconds");
startTime2 = System.currentTimeMillis();
for(int x = REPEAT ; x >= 0; --x)
{
method1(REPEAT);
method2(REPEAT);
}
endTime2 = System.currentTimeMillis();
System.out.println("Time for fused loops: " +
(endTime2 - startTime2) + " milliseconds");
}
public static void method1(final int REPEAT)
{
for(int x = REPEAT ; x >= 0; --x);
}
public static void method2(final int REPEAT)
{
for(int x = REPEAT ; x >= 0; --x);
}
}