view src/parallel_execution/TimerImpl.cbc @ 464:7d67c9cf09ee

Rename from Time interface to Timer interface
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 21 Dec 2017 00:07:27 +0900
parents src/parallel_execution/TimeImpl.cbc@8d7e5d48cad3
children ac244346c85d
line wrap: on
line source

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

#include "../context.h"
#include "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(...);
}