Quick and dirty SourcePawn inline benchmark for when you're feeling lazy. Just #include <benchmark> & wrap the tested code between BENCHMARK_START(); ... BENCHMARK_END(); Note that the START-END "stack" has to be unwound in the same LIFO order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(_BENCHMARK_INC_H_) | |
#endinput | |
#else | |
#define _BENCHMARK_INC_H_ | |
#endif | |
#include <profiler> | |
// Can nest max this many profilers, total. | |
#define MAX_PROFILERS 32 | |
#define MAX_PROFILE_SECTIONNAME_STRLEN 32 | |
static Profiler _profilers_stack[MAX_PROFILERS]; | |
static int _profilers_index = 0; | |
static char _profilers_sections[MAX_PROFILERS][MAX_PROFILE_SECTIONNAME_STRLEN]; | |
stock void BENCHMARK_START(const char[] section="unnamed") | |
{ | |
PrintToServer("BENCHMARK START: %s", section); | |
_profilers_stack[_profilers_index] = new Profiler(); | |
strcopy(_profilers_sections[_profilers_index], sizeof(_profilers_sections[]), section); | |
_profilers_stack[_profilers_index++].Start(); | |
} | |
stock void BENCHMARK_END() | |
{ | |
_profilers_stack[--_profilers_index].Stop(); | |
PrintToServer("%s FINISHED IN TIME: %f", _profilers_sections[_profilers_index], _profilers_stack[_profilers_index].Time); | |
delete _profilers_stack[_profilers_index]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment