-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
47 lines (39 loc) · 840 Bytes
/
util.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "util.h"
#include <cstdlib>
#include <vector>
#include <iostream>
#include <cstdio>
namespace Util
{
using namespace std;
std::string ALPHABET("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
std::string GetString(int size)
{
std::swap(ALPHABET[rand() % size],
ALPHABET[rand() % size]);;
if(size == ALPHABET.size())
return ALPHABET;
else
return ALPHABET.substr(size);
}
Timer::Timer(const string& _msg)
: msg(_msg),
start(std::chrono::high_resolution_clock::now())
{}
Timer::~Timer()
{
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> dur = end - start;
cout << msg
<< " took:"
<< dur.count()
<< "s"
<< endl;
}
std::string to_string(int i)
{
char buf[50];
sprintf(buf, "%d", i);
return string(buf);
}
}