66 , timer(target.duration)
71 state = this->shouldContinue();
72 if (iterateCnt <= 2) {
96 template <
typename... TArgs>
99 logger.
write(std::forward<TArgs>(args)...);
103 INLINE bool shouldContinue()
const {
104 switch (target.
mode) {
139 uint64_t elapsed = context.
elapsed();
163 benchmarks.
push(benchmark);
167 return benchmarks.
begin();
171 return benchmarks.
end();
175 return benchmarks.
size();
181 #if defined(__clang__)
182 asm volatile(
"" : :
"g"(value) :
"memory");
184 asm volatile(
"" : :
"i,r,m"(value) :
"memory");
186 return std::forward<T>(value);
191 asm volatile(
"" : : :
"memory");
196 std::map<std::string, Result> benchs;
203 std::ifstream ifs(path.
native());
205 while (std::getline(ifs, line)) {
206 std::size_t n = line.find_last_of(
'/');
207 if (n == std::string::npos) {
210 const std::string name =
trim(line.substr(0, n));
212 if (values.
size() != 6) {
216 result.
duration = std::stoi(values[0]);
218 result.
mean = std::stof(values[2]);
219 result.
variance = std::stof(values[3]);
220 result.
min = std::stof(values[4]);
221 result.
max = std::stof(values[5]);
223 benchs[name] = result;
229 return benchs.find(name) != benchs.end();
293 void run(
int argc,
char* argv[]);
298 Group& getGroupByName(
const std::string& groupName);
300 Outcome parseArgs(
int arcs,
char* argv[]);
304 void writeBaseline(
const std::string& name,
const Result& measured);
306 Path getBaselinePath();
310 template <
typename... TArgs>
311 void log(TArgs&&... args);
313 template <
typename... TArgs>
314 void logError(TArgs&&... args);
326 #define BENCHMARK_UNIQUE_NAME_IMPL(prefix, line) prefix##line
328 #define BENCHMARK_UNIQUE_NAME(prefix, line) BENCHMARK_UNIQUE_NAME_IMPL(prefix, line)
330 #define BENCHMARK_FUNCTION_NAME BENCHMARK_UNIQUE_NAME(BENCHMARK, __LINE__)
332 #define BENCHMARK_REGISTER_NAME BENCHMARK_UNIQUE_NAME(REGISTER, __LINE__)
334 #define BENCHMARK(name, group, ...) \
335 static void BENCHMARK_FUNCTION_NAME(__VA_ARGS__); \
337 ::Sph::Benchmark::Register BENCHMARK_REGISTER_NAME( \
338 makeShared<::Sph::Benchmark::Unit>(name, &BENCHMARK_FUNCTION_NAME), \
341 static void BENCHMARK_FUNCTION_NAME(__VA_ARGS__)
Generic dynamically allocated resizable storage.
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Wrapper of type containing either a value or an error message.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Logging routines of the run.
#define INLINE
Macros for conditional compilation based on selected compiler.
Return value of function that may fail, containing either SUCCEES (true) or error message.
const SuccessTag SUCCESS
Global constant for successful outcome.
Object representing a path on a filesystem, similar to std::filesystem::path in c++17.
@ RUN_AGAINST_BASELINE
Compare iteration numbers with recorded baseline.
@ MAKE_BASELINE
Store iteration numbers to baseline file.
@ SIMPLE
Just run benchmarks and report statistics.
INLINE T && doNotOptimize(T &&value)
INLINE void clobberMemory()
std::string trim(const std::string &s)
Removes all leading and trailing spaces from a string.
Array< std::string > split(const std::string &s, const char delimiter)
Splits a string into an array of string using given delimiter.
Measuring time intervals and executing periodic events.
#define NAMESPACE_BENCHMARK_BEGIN
#define NAMESPACE_BENCHMARK_END
Generic dynamically allocated resizable storage.
INLINE Iterator< StorageType > end() noexcept
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
INLINE TCounter size() const noexcept
INLINE Iterator< StorageType > begin() noexcept
bool parse(const Path &path)
INLINE Result operator[](const std::string &name)
bool isRecorded(const std::string &name)
Accessible from benchmarks.
INLINE bool running()
Whether to keep running or exit.
INLINE uint64_t elapsed() const
Context(const Target target, const std::string &name)
INLINE void log(TArgs &&... args)
Writes given message into the logger.
INLINE Stats getStats() const
INLINE Size iterationCnt() const
Wrapper of type that either contains a value of given type, or an error message.
Group(const std::string &name)
void addBenchmark(const SharedPtr< Unit > &benchmark)
const std::string & getName() const
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.
Object representing a path on a filesystem.
std::string native() const
Returns the native version of the path.
Register(const SharedPtr< Unit > &benchmark, const std::string &groupName)
void run(int argc, char *argv[])
Runs all benchmarks.
struct Session::@0::@1 baseline
std::string group
Run only selected group of benchmarks.
void registerBenchmark(const SharedPtr< Unit > &benchmark, const std::string &groupName)
Adds a new benchmark into the session.
uint64_t maxAllowedDuration
static Session & getInstance()
Array< std::string > benchmarksToRun
INLINE void add(const Float value)
INLINE Float mean() const
INLINE Float variance() const
Basic time-measuring tool. Starts automatically when constructed.
bool isExpired() const
Checks if the interval has already passed.
int64_t elapsed(const TimerUnit unit) const
Returns elapsed time in timer units. Does not reset the timer.
void restart()
Reset elapsed duration to zero.
Expected< Result > run(const Target target)
const std::string & getName() const
Unit(const std::string &name, const Function func)