diff options
author | 2021-03-10 15:34:55 +0200 | |
---|---|---|
committer | 2021-03-10 15:34:55 +0200 | |
commit | b36a641c699dcd21e82aaa73971f9744dac61aa1 (patch) | |
tree | 8a755d945a7fd24930c83f7c5c4d0d2b94e9d130 /src/main.c | |
parent | 8788b9b33ec46e3f96170fb35a70a03addbf9671 (diff) | |
download | algos-ld1-b36a641c699dcd21e82aaa73971f9744dac61aa1.tar.gz algos-ld1-b36a641c699dcd21e82aaa73971f9744dac61aa1.tar.bz2 algos-ld1-b36a641c699dcd21e82aaa73971f9744dac61aa1.zip |
move benching to its own function.
This allows us to cleanly reuse the code for uncached runs.
Also refactor for readability and such.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 49 |
1 files changed, 36 insertions, 13 deletions
@@ -17,6 +17,7 @@ static struct settings settings = {0, 0, 0, NULL, NULL, mode_normal, array, cached}; +static int bench (struct stream * const in, struct stream * const out); static int parseargs(int argc, char **argv, struct settings * settings); static int load_io_functions(struct settings const * const s, struct stream * const in); static void printhelp(const char * const name); @@ -29,8 +30,6 @@ static struct stream file_in = stream_blank; static struct stream file_out = stream_blank; static struct stream file_tmp = stream_blank; -static struct rin_bench_result bongholio; - int main(int argc, char **argv) { int ret = 0; @@ -75,19 +74,9 @@ int main(int argc, char **argv) try_s((ret = cache_transfer(&file_in, &file_out)), out); break; case mode_normal: - - /* BENCHMARK STARTS HERE */ - rin_bench_start(); - try_s((ret = merge_sort(&file_in, &file_tmp)), out); - rin_bench_stop(&bongholio); - /* BENCHMARK ENDS HERE */ - rin_info("wall: %lus %3lums %3luµs", bongholio.wall.tv_sec, bongholio.wall.tv_nsec / (1000 * 1000), (bongholio.wall.tv_nsec / 1000) % 1000); - rin_info("system: %lus %3lums %3luµs", bongholio.system.tv_sec, bongholio.system.tv_usec / 1000, bongholio.system.tv_usec % 1000); - rin_info("user: %lus %3lums %3luµs", bongholio.user.tv_sec, bongholio.user.tv_usec / 1000, bongholio.user.tv_usec % 1000); - rin_info("total: %lus %3lums %3luµs", bongholio.total.tv_sec, bongholio.total.tv_usec / 1000, bongholio.total.tv_usec % 1000); + bench(&file_in, &file_tmp); try_s((ret = cache_transfer(&file_tmp, &file_out)), out); } - } else { /* uncached */ /* TODO */ } @@ -108,6 +97,40 @@ early_out: return ret; } +static int bench(struct stream * const in, struct stream * const out) +{ + int ret; + struct rin_bench_result bongholio; + + /* BENCHMARK STARTS HERE */ + rin_bench_start(); + + try_s((ret = merge_sort(in, out)), err); + + /* BENCHMARK ENDS HERE */ + rin_bench_stop(&bongholio); + + rin_info("wall: %lus %3lums %3luµs", + bongholio.wall.tv_sec, + bongholio.wall.tv_nsec / (1000 * 1000), + (bongholio.wall.tv_nsec / 1000) % 1000); + rin_info("system: %lus %3lums %3luµs", + bongholio.system.tv_sec, + bongholio.system.tv_usec / 1000, + bongholio.system.tv_usec % 1000); + rin_info("user: %lus %3lums %3luµs", + bongholio.user.tv_sec, + bongholio.user.tv_usec / 1000, + bongholio.user.tv_usec % 1000); + rin_info("total: %lus %3lums %3luµs", + bongholio.total.tv_sec, + bongholio.total.tv_usec / 1000, + bongholio.total.tv_usec % 1000); + +err: + return ret; +} + static int parseargs(int argc, char **argv, struct settings * settings) { struct settings s = {0}; |