在尝试优化代码时,我对kcachegrdind
和生成的配置文件的差异感到有些困惑gprof
。具体来说,如果我使用 gprof(使用-pg
switch 编译等),我有这个:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
89.62 3.71 3.71 204626 0.02 0.02 objR<true>::R_impl(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&) const
5.56 3.94 0.23 18018180 0.00 0.00 W2(coords_t const&, coords_t const&)
3.87 4.10 0.16 200202 0.00 0.00 build_matrix(std::vector<coords_t, std::allocator<coords_t> > const&)
0.24 4.11 0.01 400406 0.00 0.00 std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&)
0.24 4.12 0.01 100000 0.00 0.00 Wrat(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<coords_t, std::allocator<coords_t> > const&)
0.24 4.13 0.01 9 1.11 1.11 std::vector<short, std::allocator<short> >* std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<std::vector<short, std::alloca
这似乎表明我不需要费心去寻找任何地方,但::R_impl(...)
同时,如果我在没有-pg
开关的情况下编译并运行valgrind --tool=callgrind ./a.out
,我有一些相当不同的东西:这是kcachegrind
输出的屏幕截图
如果我正确地解释了这一点,这似乎表明::R_impl(...)
只需要大约 50% 的时间,而另一半则用于线性代数(Wrat(...)
和eigenvalues
底层的 lapack 调用),这在配置文件的下方gprof
。
我理解这一点gprof
并cachegrind
使用不同的技术,如果他们的结果有些不同,我不会打扰。但是在这里,它看起来非常不同,我不知道如何解释这些。有什么想法或建议吗?