Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
Created May 11, 2022 19:00
Show Gist options
  • Save h4k1m0u/8b30934fca223813f23f74f8e6512120 to your computer and use it in GitHub Desktop.
Save h4k1m0u/8b30934fca223813f23f74f8e6512120 to your computer and use it in GitHub Desktop.
Calculate execution time in C
#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