2019-04-22 22:01:55 -05:00
|
|
|
// 22 april 2019
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#include <mach/mach_time.h>
|
|
|
|
#include "testing.h"
|
2019-04-29 22:46:08 -05:00
|
|
|
#include "testingpriv.h"
|
2019-04-22 22:01:55 -05:00
|
|
|
|
|
|
|
struct testingTimer {
|
|
|
|
uint64_t start;
|
|
|
|
uint64_t end;
|
|
|
|
};
|
|
|
|
|
|
|
|
testingTimer *testingNewTimer(void)
|
|
|
|
{
|
2019-04-29 22:46:08 -05:00
|
|
|
return testingprivNew(testingTimer);
|
2019-04-22 22:01:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testingFreeTimer(testingTimer *t)
|
|
|
|
{
|
2019-04-29 22:46:08 -05:00
|
|
|
testingprivFree(t);
|
2019-04-22 22:01:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testingTimerStart(testingTimer *t)
|
|
|
|
{
|
|
|
|
t->start = mach_absolute_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
void testingTimerEnd(testingTimer *t)
|
|
|
|
{
|
|
|
|
t->end = mach_absolute_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t testingTimerNsec(testingTimer *t)
|
|
|
|
{
|
|
|
|
mach_timebase_info_data_t mt;
|
|
|
|
uint64_t c;
|
|
|
|
|
|
|
|
mach_timebase_info(&mt);
|
|
|
|
c = t->end - t->start;
|
|
|
|
c = c * mt.numer / mt.denom;
|
|
|
|
return (int64_t) c;
|
|
|
|
}
|