view src/parallel_execution/TimerImpl.cbc @ 557:1eb2a22ec1e3

tweak
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 18 Nov 2019 21:22:34 +0900
parents b8b412a7670a
children
line wrap: on
line source

#include <stdio.h>
#include <sys/time.h>

#include "../context.h"
#interface "Timer.h"

Timer* createTimerImpl(struct Context* context) {
    struct Timer* timer = new Timer();
    struct TimerImpl* timerImpl = new TimerImpl();
    timer->timer = (union Data*)timerImpl;
    timer->start = C_startTimer;
    timer->end = C_endTimer;
    return timer;
}

__code startTimer(struct TimerImpl* timer, __code next(...)) {
    struct timeval tv;
    gettimeofday(&tv, NULL);

    timer->time = tv.tv_sec + (double)tv.tv_usec*1e-6;

    goto next(...);
}

__code endTimer(struct TimerImpl* timer, __code next(...)) {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    printf("%0.6f\n", (tv.tv_sec+(double)tv.tv_usec*1e-6) - timer->time);
    goto next(...);
}