Feat: run multiple benchmarking cycles
This commit is contained in:
parent
61be4c0382
commit
44bff07e02
3 changed files with 18 additions and 11 deletions
|
@ -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
|
|
@ -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();
|
||||
for (; cycles > 0; cycles--) {
|
||||
func(len, buf, out);
|
||||
}
|
||||
double end = current_time();
|
||||
|
||||
return end - start;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue