From 5b4db091df123f7c7d42be8d3b787d07c0c61f3e Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 4 Aug 2017 23:08:22 +0200 Subject: [PATCH] Add a benchmark mode --- test/default/cmptest.h | 46 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/test/default/cmptest.h b/test/default/cmptest.h index 96a0ad76..bf3ddb68 100644 --- a/test/default/cmptest.h +++ b/test/default/cmptest.h @@ -30,7 +30,51 @@ int xmain(void); -#ifndef BROWSER_TESTS +#ifdef BENCHMARKS + +# include + +# define ITERATIONS 256 + +static unsigned long long now(void) +{ + struct timeval tp; + unsigned long long now; + + if (gettimeofday(&tp, NULL) != 0) { + abort(); + } + now = ((unsigned long long) tp.tv_sec * 1000000ULL) + + (unsigned long long) tp.tv_usec; + + return now; +} + +int main(void) +{ + unsigned long long ts_start; + unsigned long long ts_end; + unsigned int i; + + if (sodium_init() != 0) { + return 99; + } + randombytes_set_implementation(&randombytes_salsa20_implementation); + ts_start = now(); + for (i = 0; i < ITERATIONS; i++) { + if (xmain() != 0) { + abort(); + } + } + ts_end = now(); + printf("%llu\n", ts_end - ts_start); + + return 0; +} + +#define printf(...) do { } while(0) + +#elif !defined(BROWSER_TESTS) FILE *fp_res;