Skip to content

Instantly share code, notes, and snippets.

@Jerrylum
Created October 26, 2021 10:42
Show Gist options
  • Save Jerrylum/19654ad218f82a02075e71a796e09767 to your computer and use it in GitHub Desktop.
Save Jerrylum/19654ad218f82a02075e71a796e09767 to your computer and use it in GitHub Desktop.
Lazy time test macro
#define TIMETEST(name, content) struct timeval tval_before_##name, tval_after_##name, tval_result_##name; \
gettimeofday(&tval_before_##name, NULL); \
content \
gettimeofday(&tval_after_##name, NULL); \
timersub(&tval_after_##name, &tval_before_##name, &tval_result_##name); \
printf(#name " %ld.%06ld\n", (long int)tval_result_##name.tv_sec, (long int)tval_result_##name.tv_usec);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment