mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-22 04:21:08 +00:00
Unbreak the performance tests.
This commit is contained in:
parent
b7c8a6f6ae
commit
6da2e5388a
2 changed files with 24 additions and 54 deletions
40
t/t_md5.c
40
t/t_md5.c
|
@ -176,12 +176,13 @@ t_md5_vector(char **desc CRYB_UNUSED, void *arg)
|
||||||
*/
|
*/
|
||||||
#define T_PERF_ITERATIONS 1000
|
#define T_PERF_ITERATIONS 1000
|
||||||
static int
|
static int
|
||||||
t_md5_perf(char **desc CRYB_UNUSED, void *arg)
|
t_md5_perf(char **desc, void *arg)
|
||||||
{
|
{
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[MD5_DIGEST_LEN];
|
uint8_t digest[MD5_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
char *msg, *comment;
|
||||||
|
size_t msglen = *(size_t *)arg;
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
if ((msg = calloc(1, msglen)) == NULL)
|
||||||
err(1, "calloc()");
|
err(1, "calloc()");
|
||||||
|
@ -196,7 +197,7 @@ t_md5_perf(char **desc CRYB_UNUSED, void *arg)
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
if (comment == NULL)
|
||||||
err(1, "asprintf()");
|
err(1, "asprintf()");
|
||||||
*desc = (const char *)comment;
|
*desc = comment;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -224,31 +225,6 @@ t_md5_short_updates(char **desc CRYB_UNUSED, void *arg)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
* Boilerplate
|
||||||
|
@ -278,7 +254,15 @@ t_prepare(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
t_add_test(t_md5_short_updates, &t_md5_vectors[6],
|
t_add_test(t_md5_short_updates, &t_md5_vectors[6],
|
||||||
"multiple short updates");
|
"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
|
#endif
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
38
t/t_sha1.c
38
t/t_sha1.c
|
@ -196,12 +196,13 @@ t_sha1_short_updates(char **desc CRYB_UNUSED, void *arg)
|
||||||
*/
|
*/
|
||||||
#define T_PERF_ITERATIONS 1000
|
#define T_PERF_ITERATIONS 1000
|
||||||
static int
|
static int
|
||||||
t_sha1_perf(const char **desc, void *arg)
|
t_sha1_perf(char **desc, void *arg)
|
||||||
{
|
{
|
||||||
struct timespec ts, te;
|
struct timespec ts, te;
|
||||||
unsigned long ns;
|
unsigned long ns;
|
||||||
uint8_t digest[SHA1_DIGEST_LEN];
|
uint8_t digest[SHA1_DIGEST_LEN];
|
||||||
char *msg, *comment;
|
char *msg, *comment;
|
||||||
|
size_t msglen = *(size_t *)arg;
|
||||||
|
|
||||||
if ((msg = calloc(1, msglen)) == NULL)
|
if ((msg = calloc(1, msglen)) == NULL)
|
||||||
err(1, "calloc()");
|
err(1, "calloc()");
|
||||||
|
@ -216,35 +217,11 @@ t_sha1_perf(const char **desc, void *arg)
|
||||||
msglen, T_PERF_ITERATIONS, ns);
|
msglen, T_PERF_ITERATIONS, ns);
|
||||||
if (comment == NULL)
|
if (comment == NULL)
|
||||||
err(1, "asprintf()");
|
err(1, "asprintf()");
|
||||||
*desc = (const char *)comment;
|
*desc = comment;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
* Boilerplate
|
||||||
|
@ -274,6 +251,15 @@ t_prepare(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
t_add_test(t_sha1_short_updates, &t_sha1_vectors[4],
|
t_add_test(t_sha1_short_updates, &t_sha1_vectors[4],
|
||||||
"multiple short updates");
|
"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
|
#endif
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue