-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.java
61 lines (51 loc) · 1.11 KB
/
Matrix.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package fibb;
import java.util.ArrayList;
import java.util.Collections;
public class Matrix {
final static int TAM = 500;
static int[][] m1;
static int[][] m2;
static int[][] mr;
static ArrayList<Long> tiempos = new ArrayList<>(TAM);
public static int pp(int a, int b, int n){
int res = 0;
for(int i = 0; i < n; i++){
res = res + (m1[a][i]*m2[i][b]);
}
return res;
}
public static Long multiplicarMatriz(int n){
Long ti, tpi;
ti = System.nanoTime();
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
mr[i][j]= pp(i,j,n);
}
}
tpi = (System.nanoTime() - ti)/n*n;
return tpi;
}
public static void main(String[] args){
Long res;
for(int n = 10; n < TAM ; n ++){
res = 0l;
m1 = new int[n][n];
m2 = new int[n][n];
mr = new int[n][n];
// for(int i = 0; i < 10; i++){
// for(int j = 0; j < 10; j++){
// m1[i][j]=1;
// m2[i][j]=1;
// }
//
// }
for (int i = 0; i < 10; i++){
res += multiplicarMatriz(n);
}
tiempos.add((res/10l));
}
for(int i = 0; i < TAM-10; i++){
System.out.println(tiempos.get(i));
}
}
}