From 6da2e5388a809706064ee6229f2a6af676d72c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Thu, 10 Jul 2014 13:30:48 +0000 Subject: [PATCH] Unbreak the performance tests. --- t/t_md5.c | 40 ++++++++++++---------------------------- t/t_sha1.c | 38 ++++++++++++-------------------------- 2 files changed, 24 insertions(+), 54 deletions(-) diff --git a/t/t_md5.c b/t/t_md5.c index ac6af6a..f8ac3cd 100644 --- a/t/t_md5.c +++ b/t/t_md5.c @@ -176,12 +176,13 @@ t_md5_vector(char **desc CRYB_UNUSED, void *arg) */ #define T_PERF_ITERATIONS 1000 static int -t_md5_perf(char **desc CRYB_UNUSED, void *arg) +t_md5_perf(char **desc, void *arg) { struct timespec ts, te; unsigned long ns; uint8_t digest[MD5_DIGEST_LEN]; char *msg, *comment; + size_t msglen = *(size_t *)arg; if ((msg = calloc(1, msglen)) == NULL) err(1, "calloc()"); @@ -196,7 +197,7 @@ t_md5_perf(char **desc CRYB_UNUSED, void *arg) msglen, T_PERF_ITERATIONS, ns); if (comment == NULL) err(1, "asprintf()"); - *desc = (const char *)comment; + *desc = comment; return (1); } #endif @@ -224,31 +225,6 @@ t_md5_short_updates(char **desc CRYB_UNUSED, void *arg) } #endif - -#ifdef BENCHMARKS -/* - * Microbenchmarks - */ -int -t_md5_perf_0, "microbenchmark with empty message") -{ - - return (t_md5_perf(0, desc)); -} - -T_FUNC(perf_1000, "microbenchmark with 1,000-byte message") -{ - - return (t_md5_perf(1000, desc)); -} - -T_FUNC(perf_1000000, "microbenchmark with 1,000,000-byte message") -{ - - return (t_md5_perf(1000000, desc)); -} -#endif - /*************************************************************************** * Boilerplate @@ -278,7 +254,15 @@ t_prepare(int argc, char *argv[]) */ t_add_test(t_md5_short_updates, &t_md5_vectors[6], "multiple short updates"); -// t_add_test(t_md5_partial +#endif +#ifdef BENCHMARKS + static size_t one = 1, thousand = 1000, million = 1000000; + t_add_test(t_md5_perf, &one, + "performance test (1 byte)"); + t_add_test(t_md5_perf, &thousand, + "performance test (1,000 bytes)"); + t_add_test(t_md5_perf, &million, + "performance test (1,000,000 bytes)"); #endif return (0); } diff --git a/t/t_sha1.c b/t/t_sha1.c index 9234fc6..ffda4a4 100644 --- a/t/t_sha1.c +++ b/t/t_sha1.c @@ -196,12 +196,13 @@ t_sha1_short_updates(char **desc CRYB_UNUSED, void *arg) */ #define T_PERF_ITERATIONS 1000 static int -t_sha1_perf(const char **desc, void *arg) +t_sha1_perf(char **desc, void *arg) { struct timespec ts, te; unsigned long ns; uint8_t digest[SHA1_DIGEST_LEN]; char *msg, *comment; + size_t msglen = *(size_t *)arg; if ((msg = calloc(1, msglen)) == NULL) err(1, "calloc()"); @@ -216,35 +217,11 @@ t_sha1_perf(const char **desc, void *arg) msglen, T_PERF_ITERATIONS, ns); if (comment == NULL) err(1, "asprintf()"); - *desc = (const char *)comment; + *desc = comment; return (1); } #endif - -#ifdef BENCHMARKS -/* - * Microbenchmarks - */ -T_FUNC(perf_0, "microbenchmark with empty message") -{ - - return (t_sha1_perf(0, desc)); -} - -T_FUNC(perf_1000, "microbenchmark with 1,000-byte message") -{ - - return (t_sha1_perf(1000, desc)); -} - -T_FUNC(perf_1000000, "microbenchmark with 1,000,000-byte message") -{ - - return (t_sha1_perf(1000000, desc)); -} -#endif - /*************************************************************************** * Boilerplate @@ -274,6 +251,15 @@ t_prepare(int argc, char *argv[]) */ t_add_test(t_sha1_short_updates, &t_sha1_vectors[4], "multiple short updates"); +#endif +#ifdef BENCHMARKS + static size_t one = 1, thousand = 1000, million = 1000000; + t_add_test(t_sha1_perf, &one, + "performance test (1 byte)"); + t_add_test(t_sha1_perf, &thousand, + "performance test (1,000 bytes)"); + t_add_test(t_sha1_perf, &million, + "performance test (1,000,000 bytes)"); #endif return (0); }