-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcJava.java
More file actions
40 lines (30 loc) · 993 Bytes
/
CalcJava.java
File metadata and controls
40 lines (30 loc) · 993 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
35
36
37
38
39
40
public class CalcJava {
private static final long NANO_CONV_MS = 1_000_000;
public static void main(String[] args) {
int n = 1000;
if (args.length > 0) {
n = Integer.parseInt(args[0]);
}
long[] A = new long[n * n];
long[] B = new long[n * n];
long[] C = new long[n * n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
A[i*n + j] = i + j;
B[i*n + j] = i - j;
}
}
final long start = System.nanoTime();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
C[i*n + j] += A[i*n + k] * B[k*n + j];
}
}
}
final long end = System.nanoTime();
final long durationMs = (end - start) / NANO_CONV_MS;
System.out.println(durationMs + "ms");
System.out.println(C[0]);
}
}