aboutsummaryrefslogtreecommitdiff
path: root/src/bench/Examples.cpp
diff options
context:
space:
mode:
authorMax K <[email protected]>2019-06-20 14:58:05 +0200
committerGitHub <[email protected]>2019-06-20 14:58:05 +0200
commit458b4a7ee93b0f8c94c7a5de0c110bfda2335d6c (patch)
tree624ce269edf96c4a4e840540d894d056676bce7f /src/bench/Examples.cpp
parentRevert "Change fPIE to fPIC (#1420)" (#1447) (diff)
parentUpdate issue template (diff)
downloaddiscoin-458b4a7ee93b0f8c94c7a5de0c110bfda2335d6c.tar.xz
discoin-458b4a7ee93b0f8c94c7a5de0c110bfda2335d6c.zip
Merge pull request #1587 from langerhans/masterv1.14.0
Merge 1.14 into master
Diffstat (limited to 'src/bench/Examples.cpp')
-rw-r--r--src/bench/Examples.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/bench/Examples.cpp b/src/bench/Examples.cpp
new file mode 100644
index 000000000..314947d48
--- /dev/null
+++ b/src/bench/Examples.cpp
@@ -0,0 +1,34 @@
+// Copyright (c) 2015-2016 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include "bench.h"
+#include "validation.h"
+#include "utiltime.h"
+
+// Sanity test: this should loop ten times, and
+// min/max/average should be close to 100ms.
+static void Sleep100ms(benchmark::State& state)
+{
+ while (state.KeepRunning()) {
+ MilliSleep(100);
+ }
+}
+
+BENCHMARK(Sleep100ms);
+
+// Extremely fast-running benchmark:
+#include <math.h>
+
+volatile double sum = 0.0; // volatile, global so not optimized away
+
+static void Trig(benchmark::State& state)
+{
+ double d = 0.01;
+ while (state.KeepRunning()) {
+ sum += sin(d);
+ d += 0.000001;
+ }
+}
+
+BENCHMARK(Trig);