我想为一些函数执行时间,我自己写了一个帮手:
using namespace std;
template<int N = 1, class Fun, class... Args>
void timeExec(string name, Fun fun, Args... args) {
auto start = chrono::steady_clock::now();
for(int i = 0; i < N; ++i) {
fun(args...);
}
auto end = chrono::steady_clock::now();
auto diff = end - start;
cout << name << ": "<< chrono::duration<double, milli>(diff).count() << " ms. << endl;
}
Run Code Online (Sandbox Code Playgroud)
我认为对于计时成员函数这种方式我必须使用bind或lambda,我想看看哪个会影响性能,所以我做了:
const int TIMES = 10000;
timeExec<TIMES>("Bind evaluation", bind(&decltype(result)::eval, &result));
timeExec<1>("Lambda evaluation", [&]() {
for(int i = 0; i < TIMES; …Run Code Online (Sandbox Code Playgroud) 假设我在Theano中实现了以下功能:
import theano.tensor as T
from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,构造了一个计算图,该函数得到优化和编译.
如何在Python脚本和/或C++应用程序中重用这个编译好的代码块?
编辑: 目标是构建一个深度学习网络并在最终的C++应用程序中重用它.