Skip to content

Instantly share code, notes, and snippets.

@cramsay
Created October 29, 2013 16:52
Show Gist options
  • Save cramsay/7218427 to your computer and use it in GitHub Desktop.
Save cramsay/7218427 to your computer and use it in GitHub Desktop.
Smeed: C time macros - second based.
#include <time.h>
/* The following timing-related macros are based on the reaction.c
* versions except that they are time_t and time() specific rather
* than clock_t and clock() specific since the latter aren't
* suitable for timing I/O bound programs.
*/
static time_t _startTime,_stopTime; /* 'private' variables */
#define SNAP() (_startTime = time(NULL))
#define SHOT() (_stopTime = time(NULL))
#define ELAPSED() (difftime(_stopTime,_startTime))
#define RUNTIME() (difftime(time(NULL),_startTime))
/* PAUSE(): a crude delay system - it waits for d seconds to expire. */
#define PAUSE(d) {SNAP();while ((int)RUNTIME() < d);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment