acl/lib_acl_cpp/samples/util.cpp

21 lines
436 B
C++
Raw Normal View History

#include "stdafx.h"
#include <string.h>
2015-05-21 21:49:35 +08:00
#include <time.h>
2014-11-19 00:25:21 +08:00
#include "util.h"
double util::stamp_sub(const struct timeval *from, const struct timeval *sub_by)
{
struct timeval res;
memcpy(&res, from, sizeof(struct timeval));
res.tv_usec -= sub_by->tv_usec;
if (res.tv_usec < 0) {
--res.tv_sec;
res.tv_usec += 1000000;
}
res.tv_sec -= sub_by->tv_sec;
return (res.tv_sec * 1000.0 + res.tv_usec/1000.0);
}