diff --git a/Implementierung/lib/helper.h b/Implementierung/lib/helper.h index 6d5ecfb..c564623 100644 --- a/Implementierung/lib/helper.h +++ b/Implementierung/lib/helper.h @@ -38,13 +38,14 @@ enum argumentParseResult parseArguments(int argc, char** argv, /** * @brief Run an md2_hash_func with benchmark timing * + * @param cycles the number of cycles to execute * @param func the function to run * @param len the lenght of buf * @param buf the data to hash * @param out the target array for the hash * @return double */ -double run_benchmark(md2_hash_func func, size_t len, uint8_t* buf, - uint8_t* out); +double run_benchmark(unsigned cycles, md2_hash_func func, size_t len, + uint8_t* buf, uint8_t* out); #endif // HELPER_H \ No newline at end of file diff --git a/Implementierung/src/helper.c b/Implementierung/src/helper.c index a32625a..4e4db31 100644 --- a/Implementierung/src/helper.c +++ b/Implementierung/src/helper.c @@ -93,10 +93,12 @@ double current_time(void) { return t.tv_sec + t.tv_nsec * 1e-9; } -double run_benchmark(md2_hash_func func, size_t len, uint8_t *buf, - uint8_t *out) { +double run_benchmark(unsigned cycles, md2_hash_func func, size_t len, + uint8_t *buf, uint8_t *out) { double start = current_time(); - func(len, buf, out); + for (; cycles > 0; cycles--) { + func(len, buf, out); + } double end = current_time(); return end - start; diff --git a/Implementierung/src/main.c b/Implementierung/src/main.c index 8ab1411..173d6e7 100644 --- a/Implementierung/src/main.c +++ b/Implementierung/src/main.c @@ -8,7 +8,7 @@ static bool runTest(const char* message, const char* expectedHash) { uint8_t out[16]; double duration = - run_benchmark(md2_hash, strlen(message), (uint8_t*)message, out); + run_benchmark(1, md2_hash, strlen(message), (uint8_t*)message, out); char hash[32]; md2_encode_hash(out, hash); @@ -86,13 +86,17 @@ int main(int argc, char** argv) { printf("\n"); uint8_t out[16]; - double duration = run_benchmark(md2_hash, len, data, out); - - printf("Hash: "); char hash[32]; + if (c.doBenchmark) { + double duration = + run_benchmark(c.benchmarkingCycles, md2_hash, len, data, out); + printf("Running %d cycles took %f seconds\n", c.benchmarkingCycles, + duration); + } else { + md2_hash(len, data, out); + } md2_encode_hash(out, hash); - - printf("%s, took: %f\n", hash, duration); + printf("Hash: %s\n", hash); free(data);