switch to heap memory in benchmark()
This commit is contained in:
parent
55480a727e
commit
d8c3a75d50
50
main.c
50
main.c
@ -2,29 +2,33 @@
|
||||
#include "matrix.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
void benchmark() {
|
||||
const uint64_t row_length1 = 100, column_length1 = 100;
|
||||
uint64_t matrix1[row_length1][column_length1];
|
||||
const uint64_t vertex_count1 = 1024;
|
||||
// printf("vertex_count1 * vertex_count1 * sizeof(uint64_t) = %lu bytes\n", vertex_count1 * vertex_count1 * sizeof(uint64_t));
|
||||
// printf("sizeof(uint64_t[vertex_count1][vertex_count1] = %lu bytes\n", sizeof(uint64_t[vertex_count1][vertex_count1]));
|
||||
// return;
|
||||
uint64_t (*matrix1)[vertex_count1] = malloc(vertex_count1 * vertex_count1 * sizeof(uint64_t));
|
||||
|
||||
const uint64_t row_length2 = 100, column_length2 = 100;
|
||||
uint64_t matrix2[row_length2][column_length2];
|
||||
const uint64_t vertex_count2 = 1024;
|
||||
uint64_t (*matrix2)[vertex_count2] = malloc(vertex_count2 * vertex_count2 * sizeof(uint64_t));
|
||||
|
||||
uint64_t new_matrix[row_length1][column_length2];
|
||||
uint64_t (*new_matrix)[vertex_count2] = malloc(vertex_count1 * vertex_count2 * sizeof(uint64_t));
|
||||
|
||||
double elapsed_time = 0.0;
|
||||
const uint64_t iterations = 10000;
|
||||
const uint64_t iterations = 1;
|
||||
clock_t start_time;
|
||||
|
||||
for (uint64_t i = 0; i < iterations; i++) {
|
||||
random_adjacency(row_length1, matrix1);
|
||||
random_adjacency(row_length2, matrix2);;
|
||||
random_adjacency(vertex_count1, matrix1);
|
||||
random_adjacency(vertex_count2, matrix2);
|
||||
|
||||
start_time = clock();
|
||||
|
||||
matrix_multiply_basic(row_length1, column_length1, matrix1,
|
||||
row_length2, column_length2, matrix2,
|
||||
matrix_multiply_basic(vertex_count1, vertex_count1, matrix1,
|
||||
vertex_count2, vertex_count2, matrix2,
|
||||
new_matrix);
|
||||
|
||||
elapsed_time += (double)(clock() - start_time) / CLOCKS_PER_SEC;
|
||||
@ -32,6 +36,10 @@ void benchmark() {
|
||||
|
||||
printf("%lu iterations of matrix_multiply_basic took roughly %f seconds\n", iterations, elapsed_time);
|
||||
printf("An iteration of matrix_multiply_basic took on average roughly %f seconds\n", elapsed_time/iterations);
|
||||
|
||||
free(matrix1);
|
||||
free(matrix2);
|
||||
free(new_matrix);
|
||||
}
|
||||
|
||||
void test() {
|
||||
@ -44,28 +52,6 @@ void test() {
|
||||
print_matrix(vertex_count, vertex_count, adjacency_matrix);
|
||||
puts("");
|
||||
|
||||
// uint64_t new_matrix1[vertex_count][vertex_count];
|
||||
//
|
||||
// matrix_multiply_basic(vertex_count, vertex_count, adjacency_matrix,
|
||||
// vertex_count, vertex_count, adjacency_matrix,
|
||||
// new_matrix1);
|
||||
//
|
||||
// puts("G²:");
|
||||
// print_matrix(vertex_count, vertex_count, new_matrix1);
|
||||
// puts("");
|
||||
//
|
||||
// uint64_t new_matrix2[vertex_count][vertex_count];
|
||||
//
|
||||
// copy(vertex_count, vertex_count, new_matrix1, new_matrix2);
|
||||
//
|
||||
// matrix_multiply_basic(vertex_count, vertex_count, new_matrix1,
|
||||
// vertex_count, vertex_count, adjacency_matrix,
|
||||
// new_matrix2);
|
||||
//
|
||||
// puts("G³:");
|
||||
// print_matrix(vertex_count, vertex_count, new_matrix2);
|
||||
// puts("");
|
||||
|
||||
uint64_t distance_matrix[vertex_count][vertex_count];
|
||||
|
||||
calculate_distance_matrix(vertex_count, adjacency_matrix, distance_matrix);
|
||||
|
Loading…
Reference in New Issue
Block a user