Skip to content

Commit 2f44f36

Browse files
committed
Update benchmark_read and benchmark_write
1 parent 3c615dd commit 2f44f36

File tree

2 files changed

+58
-19
lines changed

2 files changed

+58
-19
lines changed

examples/benchmark_read.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ int main(int argc, char** argv) {
6060

6161
printf("Opening %s\n", file_name);
6262

63-
const int num_trials = 10;
63+
const int num_trials = 1;
6464

6565
double durations[num_trials];
6666

6767
size_t nbytes = 0;
6868

69+
// To flush the filesystem cache before each trial, change to `true`.
70+
bool cold_cache = false;
71+
6972
for (size_t i = 0; i < num_trials; i++) {
70-
flush_cache();
73+
if (cold_cache) {
74+
flush_cache();
75+
}
7176
double begin = gettime();
7277
bsp_matrix_t mat = bsp_read_matrix(file_name, NULL);
7378
double end = gettime();
@@ -89,13 +94,17 @@ int main(int argc, char** argv) {
8994

9095
double variance = compute_variance(durations, num_trials);
9196

92-
printf("Read file in %lf seconds\n", durations[num_trials / 2]);
97+
double median_time = durations[num_trials / 2];
9398

94-
printf("Variance is %lf seconds, standard devication is %lf seconds\n",
95-
variance, sqrt(variance));
99+
printf("Read file in %lf seconds\n", median_time);
100+
101+
if (num_trials > 1) {
102+
printf("Variance is %lf seconds, standard devication is %lf seconds\n",
103+
variance, sqrt(variance));
104+
}
96105

97106
double gbytes = ((double) nbytes) / 1024 / 1024 / 1024;
98-
double gbytes_s = gbytes / durations[num_trials / 2];
107+
double gbytes_s = gbytes / median_time;
99108

100109
printf("Achieved %lf GiB/s\n", gbytes_s);
101110

@@ -108,5 +117,7 @@ int main(int argc, char** argv) {
108117
}
109118
printf("]\n");
110119

120+
printf("FORPARSER: %s,%lf,%lf\n", file_name, median_time, gbytes_s);
121+
111122
return 0;
112123
}

examples/benchmark_write.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,63 @@ void delete_file(char* file_name) {
6868

6969
int main(int argc, char** argv) {
7070
if (argc < 2) {
71-
fprintf(stderr, "usage: ./benchmark_read [file_name.h5] [optional: "
72-
"compression_level]\n");
71+
fprintf(stderr,
72+
"usage: ./benchmark_read [file_name.h5] [scratch_space] [optional: "
73+
"compression_level]\n");
7374
return 1;
7475
}
7576

7677
char* file_name = argv[1];
78+
char* scratch_space = argv[2];
7779

7880
int compression_level = 0;
7981

80-
if (argc >= 3) {
81-
compression_level = atoi(argv[2]);
82+
if (argc >= 4) {
83+
compression_level = atoi(argv[3]);
8284
}
8385

8486
printf("Opening %s\n", file_name);
8587

86-
const int num_trials = 10;
88+
const int num_trials = 1;
8789

8890
double durations[num_trials];
8991

9092
bsp_matrix_t mat = bsp_read_matrix(file_name, NULL);
9193
size_t nbytes = bsp_matrix_nbytes(mat);
9294

9395
char output_filename[2048];
94-
strncpy(output_filename, "benchmark_write_file_n.h5", 2047);
96+
strncpy(output_filename, scratch_space, 2047);
97+
strncpy(output_filename + strlen(scratch_space), "/benchmark_write_file_n.h5",
98+
2047 - strlen(scratch_space));
99+
100+
// Current output name logic does not do much.
101+
assert(num_trials <= 10);
102+
103+
// To flush the filesystem cache before each trial, change to `true`.
104+
bool cold_cache = false;
105+
106+
// To flush each write to the filesystem and include this in the timing,
107+
// change to `true`.
108+
bool flush_each_write = true;
95109

96110
for (size_t i = 0; i < num_trials; i++) {
97-
flush_cache();
98-
output_filename[21] = '0' + i;
111+
if (cold_cache) {
112+
flush_cache();
113+
}
114+
115+
output_filename[strlen(scratch_space) + 21] = '0' + i;
99116
printf("Writing to file %s\n", output_filename);
100117

101118
double begin = gettime();
102119
bsp_write_matrix(output_filename, mat, NULL, NULL, compression_level);
103-
flush_writes();
120+
121+
if (flush_each_write) {
122+
flush_writes();
123+
}
124+
104125
double end = gettime();
105126
durations[i] = end - begin;
127+
106128
delete_file(output_filename);
107129
}
108130

@@ -119,13 +141,17 @@ int main(int argc, char** argv) {
119141

120142
double variance = compute_variance(durations, num_trials);
121143

122-
printf("Wrote file in %lf seconds\n", durations[num_trials / 2]);
144+
double median_time = durations[num_trials / 2];
123145

124-
printf("Variance is %lf seconds, standard devication is %lf seconds\n",
125-
variance, sqrt(variance));
146+
printf("Wrote file in %lf seconds\n", median_time);
147+
148+
if (num_trials > 1) {
149+
printf("Variance is %lf seconds, standard devication is %lf seconds\n",
150+
variance, sqrt(variance));
151+
}
126152

127153
double gbytes = ((double) nbytes) / 1024 / 1024 / 1024;
128-
double gbytes_s = gbytes / durations[num_trials / 2];
154+
double gbytes_s = gbytes / median_time;
129155

130156
printf("Achieved %lf GiB/s\n", gbytes_s);
131157

@@ -138,5 +164,7 @@ int main(int argc, char** argv) {
138164
}
139165
printf("]\n");
140166

167+
printf("FORPARSER: %s,%lf,%lf\n", file_name, median_time, gbytes_s);
168+
141169
return 0;
142170
}

0 commit comments

Comments
 (0)