-
Notifications
You must be signed in to change notification settings - Fork 0
/
marix.java
64 lines (56 loc) · 1.77 KB
/
marix.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
62
63
64
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test.simd;
/**
*
* @author Cujo
*/
public class marix {
public double mmult(int n) {
double stime = System.currentTimeMillis();
int a[][] = new int[n][n];
int b[][] = new int[n][n];
int c[][] = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = (int) (Math.random() * 10);
b[i][j] = (int) (Math.random() * 10);
}
}
for (int i = 0; i < n; ++i) {
for (int k = 0; k < n; ++k) {
for (int j = 0; j < n; ++j) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
double etime = System.currentTimeMillis();
double out = (etime - stime) / 1000;
return out;
}
public double Non_mmult(int n) {
double stime = System.currentTimeMillis();
int a[][] = new int[n][n];
int b[][] = new int[n][n];
int c[][] = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = (int) (Math.random() * 10);
b[i][j] = (int) (Math.random() * 10);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
double etime = System.currentTimeMillis();
double out = (etime - stime) / 1000;
return out;
}
}