-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_script.h
42 lines (34 loc) · 1.5 KB
/
exec_script.h
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
#pragma once
#include <boost/python.hpp>
#include <string>
#include <tuple>
//created wrapper functoins go get exection time of python code execution
namespace boost
{
namespace python {
std::tuple<py::object, double> _exec_file(py::str file_name, py::object globals = py::object(), py::object locals = py::object())
{
py::object time_module = py::import("time");
double start_time = py::extract<double>(time_module.attr("time")());
py::object res = py::exec_file(file_name, globals, locals);
double end_time = py::extract<double>(time_module.attr("time")());
return std::make_tuple(res, end_time - start_time);
}
std::tuple<py::object, double> _exec(py::str file_name, py::object globals = py::object(), py::object locals = py::object())
{
py::object time_module = py::import("time");
double start_time = py::extract<double>(time_module.attr("time")());
py::object res = py::exec_file(file_name, globals, locals);
double end_time = py::extract<double>(time_module.attr("time")());
return std::make_tuple(res, end_time - start_time);
}
std::tuple<py::object, double> _eval(py::str file_name, py::object globals = py::object(), py::object locals = py::object())
{
py::object time_module = py::import("time");
double start_time = py::extract<double>(time_module.attr("time")());
py::object res = py::exec_file(file_name, globals, locals);
double end_time = py::extract<double>(time_module.attr("time")());
return std::make_tuple(res, end_time - start_time);
}
}
}