c++ lambda函数能够提升性能,减少函数开销
例子如下:
#include
#include
using namespace std;
#define N 10000000
void test(){
for(int i = 0; i < N; i++){}
}
int main(){
clock_t start, end;
start = clock();
test();
end = clock();
cout << "regular time:" << (double)(end - start) / CLOCKS_PER_SEC << endl;
start = clock();
[](){for(int i = 0; i < N; i++); return;};
end = clock();
cout << "lambda time: " << (double)(end - start) / CLOCKS_PER_SEC << endl;
}
相关结果:
regular time:0.004946
lambda time: 1e-06
可见,c++ lambda函数能够明显提升速度
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)