解释 gprof 输出并识别此特征函数

Interpreting gprof Output and Identifying This Eigen Function

我只是 运行 gprof 来分析我的一些代码。这是平面轮廓的前几行。第一个功能使用了超过 75% 的时间。那是什么功能?关于我如何滥用 Eigen 库,它告诉我什么?

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
 75.16    368.61   368.61                             void Eigen::internal::call_assignment_no_alias<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::internal::assign_op<double> >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&, Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::internal::assign_op<double> const&)

下面是格式更好一点的函数名称:

void Eigen::internal::call_assignment_no_alias<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 
                                               Eigen::Matrix<double, -1, 1, 0, -1, 1>, 
                                               Eigen::internal::assign_op<double>      >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&, 
                                                                                         Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, 
                                                                                         Eigen::internal::assign_op<double> const&)

此函数将一个 MatrixXd 分配给另一个:

MatrixXd a, b;
b = a;

这意味着大部分时间都花在了复制矩阵上。

因此请确保您在编译时启用了优化 (-O3),否则您的分析结果将毫无意义。如果是这样,那么请确保您通过引用而不是通过值传递矩阵,如果您使用 std::vector<MatrixXd> 等请小心