Skip to content

Commit 7ced41c

Browse files
committed
Add some benchmarking to mtx2bsp
1 parent 09ef5d9 commit 7ced41c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/mtx2bsp.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#include <binsparse/binsparse.h>
22
#include <stdio.h>
33

4+
#include <time.h>
5+
6+
double gettime() {
7+
struct timespec time;
8+
clock_gettime(CLOCK_MONOTONIC, &time);
9+
return ((double) time.tv_sec) + ((double) 1e-9) * time.tv_nsec;
10+
}
11+
412
int main(int argc, char** argv) {
513

614
if (argc < 3) {
@@ -112,26 +120,48 @@ int main(int argc, char** argv) {
112120
cJSON_AddStringToObject(user_json, "comment", m.comments);
113121

114122
printf(" === Reading file... ===\n");
123+
double begin = gettime();
115124
bsp_matrix_t matrix = bsp_mmread(input_fname);
125+
double end = gettime();
116126
printf(" === Done reading. ===\n");
117127

128+
double duration = end - begin;
129+
printf("%lf seconds reading Matrix Market file...\n", duration);
130+
118131
if (perform_suitesparse_declamping) {
132+
begin = gettime();
119133
bsp_matrix_declamp_values(matrix);
134+
end = gettime();
135+
duration = end - begin;
136+
printf("%lf seconds declamping...\n", duration);
120137
}
121138

139+
begin = gettime();
122140
matrix = bsp_matrix_minimize_values(matrix);
141+
end = gettime();
142+
duration = end - begin;
143+
printf("%lf seconds minimizing values...\n", duration);
123144

124145
if (format != BSP_COOR) {
146+
begin = gettime();
125147
bsp_matrix_t converted_matrix = bsp_convert_matrix(matrix, format);
126148
bsp_destroy_matrix_t(matrix);
127149
matrix = converted_matrix;
150+
end = gettime();
151+
duration = end - begin;
152+
printf("%lf seconds converting to %s format...\n", duration,
153+
bsp_get_matrix_format_string(format));
128154
}
129155

130156
bsp_print_matrix_info(matrix);
131157

132158
printf(" === Writing to %s... ===\n", output_fname);
159+
begin = gettime();
133160
bsp_write_matrix(output_fname, matrix, group_name, user_json,
134161
compression_level);
162+
end = gettime();
163+
duration = end - begin;
164+
printf("%lf seconds writing Binsparse file...\n", duration);
135165
printf(" === Done writing. ===\n");
136166

137167
bsp_destroy_matrix_t(matrix);

0 commit comments

Comments
 (0)