2019-04-23 11:26:52 -05:00
|
|
|
// 23 april 2019
|
2019-05-02 01:01:42 -05:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
2019-04-23 11:26:52 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "testing.h"
|
2019-04-29 22:46:08 -05:00
|
|
|
#include "testingpriv.h"
|
2019-04-23 11:26:52 -05:00
|
|
|
|
|
|
|
struct testingTimer {
|
2019-04-28 20:49:54 -05:00
|
|
|
struct timespec start;
|
|
|
|
struct timespec end;
|
2019-04-23 11:26:52 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
testingTimer *testingNewTimer(void)
|
|
|
|
{
|
2019-04-29 22:46:08 -05:00
|
|
|
return testingprivNew(testingTimer);
|
2019-04-23 11:26:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testingFreeTimer(testingTimer *t)
|
|
|
|
{
|
2019-04-29 22:46:08 -05:00
|
|
|
testingprivFree(t);
|
2019-04-23 11:26:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testingTimerStart(testingTimer *t)
|
|
|
|
{
|
2019-04-28 20:49:54 -05:00
|
|
|
// TODO check errors
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &(t->start));
|
2019-04-23 11:26:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testingTimerEnd(testingTimer *t)
|
|
|
|
{
|
2019-04-28 20:49:54 -05:00
|
|
|
// TODO check errors
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &(t->end));
|
2019-04-23 11:26:52 -05:00
|
|
|
}
|
|
|
|
|
2019-04-28 20:49:54 -05:00
|
|
|
// TODO replace with proper subtraction code
|
2019-04-23 11:26:52 -05:00
|
|
|
int64_t testingTimerNsec(testingTimer *t)
|
|
|
|
{
|
2019-04-28 20:49:54 -05:00
|
|
|
int64_t nstart, nend;
|
|
|
|
|
|
|
|
nstart = ((int64_t) (t->start.tv_sec)) * testingNsecPerSec;
|
|
|
|
nstart += t->start.tv_nsec;
|
|
|
|
nend = ((int64_t) (t->end.tv_sec)) * testingNsecPerSec;
|
|
|
|
nend += t->end.tv_nsec;
|
|
|
|
return nend - nstart;
|
2019-04-23 11:26:52 -05:00
|
|
|
}
|