-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopWatch.java
More file actions
30 lines (26 loc) · 813 Bytes
/
Copy pathStopWatch.java
File metadata and controls
30 lines (26 loc) · 813 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
/*
* Sample usage: java StopWatch 1000
* Sample usage: java StopWatch 2000
* Sample usage: java StopWatch 4000
* Sample usage: java StopWatch 8000
*/
public class StopWatch {
private final long start;
public StopWatch(){
start = System.currentTimeMillis();
}
public double elapsedTime(){
long now = System.currentTimeMillis();
return (now-start)/1000.0;
}
public static void main(String[] args){
int N = Integer.parseInt(args[0]);
int[] a = new int[N];
for (int i = 0; i < N; i++)
a[i] = StdRandom.uniform(-1000000, 1000000);
StopWatch timer = new StopWatch();
int cnt = ThreeSum.count(a);
double time = timer.elapsedTime();
StdOut.println(cnt + " triples " + time + " seconds");
}
}