Skip to content

Instantly share code, notes, and snippets.

@ursachec
Last active December 21, 2015 23:49

Revisions

  1. ursachec revised this gist Aug 30, 2013. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions mrt_timer.h
    Original file line number Diff line number Diff line change
    @@ -4,16 +4,16 @@
    #include <sys/time.h>

    #define mrt_timer_setup() \
    struct timeval mrt_te; \
    time_t mrt_start = 0, mrt_end = 0;
    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 * 1000 + (time_t)mrt_te.tv_usec / 1000);
    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 * 1000 + (time_t)mrt_te.tv_usec / 1000) - mrt_start;
    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

  2. ursachec created this gist Aug 30, 2013.
    20 changes: 20 additions & 0 deletions mrt_timer.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #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 * 1000 + (time_t)mrt_te.tv_usec / 1000);

    #define mrt_timer_stop() \
    gettimeofday(&mrt_te, NULL); \
    mrt_end = ((time_t)mrt_te.tv_sec * 1000 + (time_t)mrt_te.tv_usec / 1000) - mrt_start;

    #define mrt_timer_get_elapsed() mrt_end

    #endif