Skip to content

Instantly share code, notes, and snippets.

@ursachec
Last active December 21, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ursachec/6385082 to your computer and use it in GitHub Desktop.
Save ursachec/6385082 to your computer and use it in GitHub Desktop.
Macros for measuring running times in C.
#ifndef __mrt_timer_h__
#define __mrt_timer_h__
#include <sys/time.h>
#define mrt_timer_setup() \
struct timeval mrt_te; \
time_t mrt_start = 0, mrt_end = 0;
#define mrt_timer_start() \
gettimeofday(&mrt_te, NULL); \
mrt_start = ((time_t)mrt_te.tv_sec * 1000LL + (time_t)mrt_te.tv_usec / 1000LL);
#define mrt_timer_stop() \
gettimeofday(&mrt_te, NULL); \
mrt_end = ((time_t)mrt_te.tv_sec * 1000LL + (time_t)mrt_te.tv_usec / 1000LL) - mrt_start;
#define mrt_timer_get_elapsed() mrt_end
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment