This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <SDL2/SDL_stdinc.h> | ||
|
||
typedef struct { | ||
Uint64 start; | ||
} BENCHMARK; | ||
|
||
BENCHMARK *Benchmark_Start(void); | ||
|
||
#define Benchmark_End(...) \ | ||
Benchmark_End_Impl(__FILE__, __LINE__, __func__, __VA_ARGS__) | ||
|
||
void Benchmark_End_Impl( | ||
const char *file, int32_t line, const char *func, BENCHMARK *b, | ||
const char *message); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "benchmark.h" | ||
|
||
#include "log.h" | ||
#include "memory.h" | ||
|
||
#include <SDL2/SDL_timer.h> | ||
|
||
BENCHMARK *Benchmark_Start(void) | ||
{ | ||
BENCHMARK *const b = Memory_Alloc(sizeof(BENCHMARK)); | ||
b->start = SDL_GetPerformanceCounter(); | ||
return b; | ||
} | ||
|
||
void Benchmark_End_Impl( | ||
const char *const file, const int32_t line, const char *const func, | ||
BENCHMARK *b, const char *const message) | ||
{ | ||
const double elapsed = (double)(SDL_GetPerformanceCounter() - b->start) | ||
* 1000.0 / (double)SDL_GetPerformanceFrequency(); | ||
|
||
if (message == NULL) { | ||
Log_Message(file, line, func, "took %.02f ms", elapsed); | ||
} else { | ||
Log_Message(file, line, func, "%s: took %.02f ms", message, elapsed); | ||
} | ||
|
||
Memory_FreePointer(&b); | ||
} |