Finish Tests
This commit is contained in:
parent
3315118690
commit
4992ad603e
13 changed files with 398 additions and 53 deletions
67
Cmatrix.c
Normal file
67
Cmatrix.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// For GCC and Clang
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
void parseH(char *p);
|
||||
void parseL(char *p);
|
||||
|
||||
void matrix_multiplication(int n) {
|
||||
int **a = malloc(n * sizeof(int *));
|
||||
int **b = malloc(n * sizeof(int *));
|
||||
int **c = malloc(n * sizeof(int *));
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = malloc(n * sizeof(int));
|
||||
b[i] = malloc(n * sizeof(int));
|
||||
c[i] = malloc(n * sizeof(int));
|
||||
for (int j = 0; j < n; j++) {
|
||||
a[i][j] = rand() % 100;
|
||||
b[i][j] = rand() % 100;
|
||||
c[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
free(a[i]);
|
||||
free(b[i]);
|
||||
free(c[i]);
|
||||
}
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// Start measuring time
|
||||
struct timespec begin, end;
|
||||
clock_gettime(CLOCK_REALTIME, &begin);
|
||||
// END
|
||||
|
||||
matrix_multiplication(1500);
|
||||
|
||||
|
||||
// Stop measuring time and calculate the elapsed time
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
long seconds = end.tv_sec - begin.tv_sec;
|
||||
long nanoseconds = end.tv_nsec - begin.tv_nsec;
|
||||
double elapsed = seconds + nanoseconds * 1e-9;
|
||||
|
||||
printf("Time measured: %.10f seconds.\n", elapsed);
|
||||
//
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue