aboutsummaryrefslogtreecommitdiff
path: root/src/bench/examples.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-06-12 08:02:14 -0400
committerMarcoFalke <falke.marco@gmail.com>2018-06-12 08:02:20 -0400
commitb22115d9a3b0ab5ce35efbfee95d87cb44b3df54 (patch)
treef16cddd80b2c46c1f5d2f66660a38596b61b2939 /src/bench/examples.cpp
parent7c32b414b6325743c99fed1208bc53ab0fa1996f (diff)
parente56771365b446fa7f51a17d67f3fbe560baaa5a5 (diff)
Merge #13312: docs: Add a note about the source code filename naming convention
e56771365b Do not use uppercase characters in source code filenames (practicalswift) 419a1983ca docs: Add a note about the source code filename naming convention (practicalswift) Pull request description: Add a note about the source code filename naming convention. Tree-SHA512: 8d329bd9e19bcd26e74b0862fb0bc2369b46095dbd3e69d34859908632763abd7c3d00ccc44ee059772ad4bae4460c2bcc1c0e22fd9d8876d57e5fcd346cea4b
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..b68c9cd156
--- /dev/null
+++ b/src/bench/examples.cpp
@@ -0,0 +1,34 @@
+// Copyright (c) 2015-2017 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/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, 10);
+
+// 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, 12 * 1000 * 1000);