Changeset View
Changeset View
Standalone View
Standalone View
src/bench/bench.h
// Copyright (c) 2015-2016 The Bitcoin Core developers | // Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_BENCH_BENCH_H | #ifndef BITCOIN_BENCH_BENCH_H | ||||
#define BITCOIN_BENCH_BENCH_H | #define BITCOIN_BENCH_BENCH_H | ||||
#include <functional> | |||||
#include <limits> | |||||
#include <map> | #include <map> | ||||
#include <string> | #include <string> | ||||
#include <boost/function.hpp> | |||||
#include <boost/preprocessor/cat.hpp> | #include <boost/preprocessor/cat.hpp> | ||||
#include <boost/preprocessor/stringize.hpp> | #include <boost/preprocessor/stringize.hpp> | ||||
// Simple micro-benchmarking framework; API mostly matches a subset of the | // Simple micro-benchmarking framework; API mostly matches a subset of the | ||||
// Google Benchmark framework (see https://github.com/google/benchmark). Wny not | // Google Benchmark framework (see https://github.com/google/benchmark). Wny not | ||||
// use the Google Benchmark framework? Because adding Yet Another Dependency | // use the Google Benchmark framework? Because adding Yet Another Dependency | ||||
// (that uses cmake as its build system and has lots of features we don't need) | // (that uses cmake as its build system and has lots of features we don't need) | ||||
// isn't worth it. | // isn't worth it. | ||||
Show All 36 Lines | State(std::string _name, double _maxElapsed) | ||||
minCycles = std::numeric_limits<uint64_t>::max(); | minCycles = std::numeric_limits<uint64_t>::max(); | ||||
maxCycles = std::numeric_limits<uint64_t>::min(); | maxCycles = std::numeric_limits<uint64_t>::min(); | ||||
countMask = 1; | countMask = 1; | ||||
countMaskInv = 1. / (countMask + 1); | countMaskInv = 1. / (countMask + 1); | ||||
} | } | ||||
bool KeepRunning(); | bool KeepRunning(); | ||||
}; | }; | ||||
typedef boost::function<void(State &)> BenchFunction; | typedef std::function<void(State &)> BenchFunction; | ||||
class BenchRunner { | class BenchRunner { | ||||
typedef std::map<std::string, BenchFunction> BenchmarkMap; | typedef std::map<std::string, BenchFunction> BenchmarkMap; | ||||
static BenchmarkMap &benchmarks(); | static BenchmarkMap &benchmarks(); | ||||
public: | public: | ||||
BenchRunner(std::string name, BenchFunction func); | BenchRunner(std::string name, BenchFunction func); | ||||
Show All 10 Lines |