我试图在精简操作(例如元素和)上获得与X张量相同的性能,就像在NumPy中一样。
我为并行计算启用了西姆,但没有任何效果。
以下是基准代码:
#include <iostream>
#include "xtensor/xreducer.hpp"
#include "xtensor/xrandom.hpp"
#include <ctime>
using namespace std;
pair<double, double> timeit(int size, int n=30){
double total_clocks = 0;
double total_sum = 0;
for (int i=0;i<n;i++){
xt::xtensor<double, 1> a = xt::random::rand({size}, 0., 1.);
int start = clock();
double s = xt::sum(a, xt::evaluation_strategy::immediate)();
int end = clock();
total_sum += s; total_clocks += end-start;
}
return pair<double, double>(total_clocks/CLOCKS_PER_SEC/n, total_sum);
}
int main(int argc, char *argv[])
{
for (int i=5;i<8;i++){
int size = pow(10, i);
pair<double, double> ret = timeit(size);
cout<<"size: "<<size<< " \t " <<ret.first<<" sec\t"<<ret.second<<endl;
}
return 0;
}并在启用和不启用xsimd和所有已启用优化(-O3)的情况下编译它:
$ g++ -DXTENSOR_USE_XSIMD -O3 -march=native -I/home/--user--/install_path/include "./18. test speed 2.cpp" -o a && ./a
size: 100000 0.0001456 sec 1.49984e+06
size: 1000000 0.0013149 sec 1.50002e+07
size: 10000000 0.0125417 sec 1.49995e+08$ g++ -O3 -march=native -I/home/--user--/install_path/include "./18. test speed 2.cpp" -o a && ./a
size: 100000 0.0001433 sec 1.49984e+06
size: 1000000 0.0012621 sec 1.50002e+07
size: 10000000 0.0124868 sec 1.49995e+08顺便说一句,使用numpy的相同操作:
$ python bench.py
size: 100000 0.000030 sec
size: 1000000 0.000430 sec
size: 10000000 0.005144 sec大约快4倍!
设置
如何提高xtensor性能?)))
发布于 2019-08-11 17:07:24
https://stackoverflow.com/questions/57442255
复制相似问题