2014-12-04 20:26:54 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* Copyright (c) 2014 Pieter Wuille *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef _SECP256K1_BENCH_H_
|
|
|
|
#define _SECP256K1_BENCH_H_
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "sys/time.h"
|
|
|
|
|
|
|
|
static double gettimedouble(void) {
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return tv.tv_usec * 0.000001 + tv.tv_sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_benchmark(void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) {
|
2015-01-25 17:32:08 +00:00
|
|
|
int i;
|
2014-12-04 20:26:54 +01:00
|
|
|
double min = HUGE_VAL;
|
|
|
|
double sum = 0.0;
|
|
|
|
double max = 0.0;
|
2015-01-25 17:32:08 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
double begin, total;
|
2014-12-04 20:26:54 +01:00
|
|
|
if (setup) setup(data);
|
2015-01-25 17:32:08 +00:00
|
|
|
begin = gettimedouble();
|
2014-12-04 20:26:54 +01:00
|
|
|
benchmark(data);
|
2015-01-25 17:32:08 +00:00
|
|
|
total = gettimedouble() - begin;
|
2014-12-04 20:26:54 +01:00
|
|
|
if (teardown) teardown(data);
|
|
|
|
if (total < min) min = total;
|
|
|
|
if (total > max) max = total;
|
|
|
|
sum += total;
|
|
|
|
}
|
|
|
|
printf("min %.3fus / avg %.3fus / max %.3fus\n", min * 1000000.0 / iter, (sum / count) * 1000000.0 / iter, max * 1000000.0 / iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|