Created
February 5, 2025 13:43
-
-
Save tdaron/18a1651ecfd088c349e238ea67e3292d to your computer and use it in GitHub Desktop.
Useful macro in C to measure time some code block takes !
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
#define setupChrono() clock_t start; clock_t end; double cpu_time_used; | |
#define chrono(t, ...) start = clock();\ | |
__VA_ARGS__;\ | |
end = clock();\ | |
cpu_time_used = ((double) (end - start)) * 1000 / CLOCKS_PER_SEC; \ | |
printf("[PERFORMANCE] Name: %s | File: %s | Line: %d | Execution Time: %.3f ms\n", t,__FILE__, __LINE__, cpu_time_used); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
setupChrono should be called once per code block as it defines variables going to be used by chrono.
Necessary to be able to run chrono multiple time without redefining variables x)