aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/secp256k1/libsecp256k1/src/bench.h
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-09-28 23:46:17 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-09-28 23:46:38 +0800
commit1d20b0247c35f440d3fdc3d21de19b2d5256c3cf (patch)
treebe0bce533d5d476e4f408d1d7757b9ac416463ae /crypto/secp256k1/libsecp256k1/src/bench.h
parent7977e87ce1e9ec46a8e8275f4cf53b6281c412c7 (diff)
downloadgo-tangerine-1d20b0247c35f440d3fdc3d21de19b2d5256c3cf.tar
go-tangerine-1d20b0247c35f440d3fdc3d21de19b2d5256c3cf.tar.gz
go-tangerine-1d20b0247c35f440d3fdc3d21de19b2d5256c3cf.tar.bz2
go-tangerine-1d20b0247c35f440d3fdc3d21de19b2d5256c3cf.tar.lz
go-tangerine-1d20b0247c35f440d3fdc3d21de19b2d5256c3cf.tar.xz
go-tangerine-1d20b0247c35f440d3fdc3d21de19b2d5256c3cf.tar.zst
go-tangerine-1d20b0247c35f440d3fdc3d21de19b2d5256c3cf.zip
Update libsecp256k1
Diffstat (limited to 'crypto/secp256k1/libsecp256k1/src/bench.h')
-rw-r--r--crypto/secp256k1/libsecp256k1/src/bench.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/crypto/secp256k1/libsecp256k1/src/bench.h b/crypto/secp256k1/libsecp256k1/src/bench.h
new file mode 100644
index 000000000..3a71b4aaf
--- /dev/null
+++ b/crypto/secp256k1/libsecp256k1/src/bench.h
@@ -0,0 +1,66 @@
+/**********************************************************************
+ * 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 print_number(double x) {
+ double y = x;
+ int c = 0;
+ if (y < 0.0) {
+ y = -y;
+ }
+ while (y < 100.0) {
+ y *= 10.0;
+ c++;
+ }
+ printf("%.*f", c, x);
+}
+
+void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) {
+ int i;
+ double min = HUGE_VAL;
+ double sum = 0.0;
+ double max = 0.0;
+ for (i = 0; i < count; i++) {
+ double begin, total;
+ if (setup != NULL) {
+ setup(data);
+ }
+ begin = gettimedouble();
+ benchmark(data);
+ total = gettimedouble() - begin;
+ if (teardown != NULL) {
+ teardown(data);
+ }
+ if (total < min) {
+ min = total;
+ }
+ if (total > max) {
+ max = total;
+ }
+ sum += total;
+ }
+ printf("%s: min ", name);
+ print_number(min * 1000000.0 / iter);
+ printf("us / avg ");
+ print_number((sum / count) * 1000000.0 / iter);
+ printf("us / max ");
+ print_number(max * 1000000.0 / iter);
+ printf("us\n");
+}
+
+#endif