//
|
// Created by Scheaven on 2020/5/14.
|
//
|
|
#include "time_util.h"
|
using namespace std;
|
|
int get_run_time(struct timeval *result, struct timeval *begin, struct timeval * end)
|
{
|
if(begin->tv_sec > end->tv_sec) return -1;
|
if((begin->tv_sec == end->tv_sec) && (begin->tv_usec > end->tv_usec)) return -2;
|
result->tv_sec = end->tv_sec - begin->tv_sec;
|
result->tv_usec = end->tv_usec - begin->tv_usec;
|
|
if(result->tv_usec<0)
|
{
|
result->tv_sec--;
|
result->tv_usec += 1000000;
|
}
|
return 0;
|
}
|
|
string random_int(size_t length)
|
{
|
auto randchar= []() ->char
|
{
|
const char charset[] = "0123456789";
|
const size_t max_index = (sizeof(charset) - 1);
|
return charset[rand()%max_index];
|
};
|
std::string str(length,0);
|
std::generate_n(str.begin(),length,randchar);
|
return str;
|
}
|