派生自 Algorithm/baseDetector

Scheaven
2021-06-03 168af40fe9a3cc81c6ee16b3e81f154780c36bdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// 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;
}