Last active
February 2, 2023 19:56
-
-
Save pegvin/c8f385d17f0f09dd339981b73584abf5 to your computer and use it in GitHub Desktop.
Simple Macro Based Function Profiler in C
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
#include "simple_profiler.h" | |
#ifdef LINUX | |
#include <unistd.h> | |
#endif | |
#ifdef WINDOWS | |
#include <windows.h> | |
#endif | |
void _sleepms(int ms) { | |
#ifdef LINUX | |
usleep(sleepMs * 1000); | |
#endif | |
#ifdef WINDOWS | |
Sleep(ms); | |
#endif | |
} | |
int main(void) { | |
MEASURE_FUNC_TIME_START(); | |
_sleepms(111); | |
MEASURE_FUNC_TIME_END("_sleepms(111);"); | |
return 0; | |
} | |
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
#include <stdio.h> | |
#include <time.h> | |
clock_t __clockTimeRecorded = 0; | |
#define MEASURE_FUNC_TIME_START() __clockTimeRecorded = clock() | |
#define MEASURE_FUNC_TIME_END(strPrefix) \ | |
__clockTimeRecorded = clock() - __clockTimeRecorded; \ | |
printf("%s took %fms\n", strPrefix, ((double)__clockTimeRecorded/CLOCKS_PER_SEC) * 1000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment