小编Ada*_*rek的帖子

std :: bind vs lambda performance

我想为一些函数执行时间,我自己写了一个帮手:

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)

c++ lambda caching bind c++11

12
推荐指数
2
解决办法
8569
查看次数

重用已编译的Theano函数

假设我在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++应用程序中重用它.

c++ python-2.7 theano

8
推荐指数
1
解决办法
2796
查看次数

标签 统计

c++ ×2

bind ×1

c++11 ×1

caching ×1

lambda ×1

python-2.7 ×1

theano ×1