-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.hpp
41 lines (31 loc) · 1.16 KB
/
common.hpp
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
#pragma once
#include <chrono>
#include <fstream>
#include <vector>
#include <boost/filesystem.hpp>
std::ofstream open_ofstream(const std::string &path);
std::ifstream open_ifstream(const std::string &path);
std::ifstream open_ifstream(const boost::filesystem::path &path);
std::ofstream open_ofstream(const boost::filesystem::path &path);
std::string extract_executable_name(const std::string &cmd);
void dir_copy(const std::string &source, const std::string &dest);
std::string random_string(size_t length);
void drop_privileges();
void set_cpu_affinity(std::vector<uint32_t> cpus, pid_t pid=0);
void assert_dir_exists(const boost::filesystem::path &dir);
// Measure the time the passed callable object consumes
template<typename TimeT = std::chrono::milliseconds>
struct measure
{
template<typename F, typename ...Args>
static typename TimeT::rep execution(F func, Args&&... args)
{
namespace chr = std::chrono;
auto start = chr::system_clock::now();
// Now call the function with all the parameters you need.
func(std::forward<Args>(args)...);
auto duration = chr::duration_cast<TimeT>
(chr::system_clock::now() - start);
return duration.count();
}
};