sapphire/src/utils.h
apio 1f11d8ce4d benchmark() now takes a string
benchmark() now takes a message instead of getting the message from
__PRETTY_FUNCTION__, since it is more explicit
2022-06-22 18:16:45 +02:00

35 lines
1.0 KiB
C++

#pragma once
#include "FormatString/FormatString.hpp"
#include "sapphirepch.h"
#include <chrono>
/* Simple function to replace a substring in a string. */
bool replace(std::string& str, const std::string& from, const std::string& to);
/* Easy way of converting an int to a string without writing 5 lines of code every time you want to do it. */
std::string to_string(const int& value);
/* Easy way of converting a float to a string without writing 5 lines of code every time you want to do it. */
std::string to_string(const float& value);
/* Benchmarking utilities. */
class __benchmark_impl
{
public:
__benchmark_impl(std::string_view __function_name);
~__benchmark_impl();
static void enable();
static void disable();
static void init();
private:
std::chrono::time_point<std::chrono::high_resolution_clock> m_StartTimePoint;
std::string_view m_FunctionName;
static bool m_BenchmarkingEnabled;
bool m_InternalBenchmarkingEnabled;
};
#define benchmark(message) __benchmark_impl __benchmark_impl_timer(message)