Skip to content

Instantly share code, notes, and snippets.

Last active October 30, 2022 17:50
What would you like to do?
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.
#if defined(_BENCHMARK_INC_H_)
#include <profiler>
// Can nest max this many profilers, total.
#define MAX_PROFILERS 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);
stock void BENCHMARK_END()
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