Created
May 11, 2022 19:00
-
-
Save h4k1m0u/8b30934fca223813f23f74f8e6512120 to your computer and use it in GitHub Desktop.
Calculate execution time in C
This file contains hidden or 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> | |
#include <math.h> | |
/* https://www.educative.io/edpresso/what-is-clockt-in-c */ | |
int main() { | |
clock_t start_ticks = clock(); | |
size_t n_iters = pow(10, 9); | |
for (size_t i = 0; i < n_iters; i++) { | |
log(10); | |
} | |
clock_t end_ticks = clock(); | |
clock_t elapsed_ticks = end_ticks - start_ticks; | |
float duration = (float) elapsed_ticks / CLOCKS_PER_SEC; | |
printf("Exec. time: %f s\n", duration); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment