aboutsummaryrefslogtreecommitdiff
path: root/src/bench/Examples.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-10-06 16:22:03 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-10-06 16:34:23 +0200
commitb7d78fd0bd244b324ded4131c1dd0ec81a87d15d (patch)
tree4f7a368c21fe6fb44ba61aeb2837429cb39ce27b /src/bench/Examples.cpp
parent66a86a3edb94e4769dd318f49dbe3f306274aa2c (diff)
parent7072c544b52774ac5a22835121e8e2747ad61158 (diff)
downloadbitcoin-b7d78fd0bd244b324ded4131c1dd0ec81a87d15d.tar.xz
Merge pull request #6733
7072c54 Support very-fast-running benchmarks (Gavin Andresen) 535ed92 Simple benchmarking framework (Gavin Andresen)
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 0000000000..b6b020a971
--- /dev/null
+++ b/src/bench/Examples.cpp
@@ -0,0 +1,34 @@
+// Copyright (c) 2015 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 "main.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);