Avatar ·

Profiling C++ code on Linux: how to find bottlenecks?

Hello colleagues! I'm writing a high-load C++ application on Linux. I've encountered a problem: the program runs slower than expected, but I can't figure out where exactly the performance is being lost. I tried inserting manual time measurements with std::chrono, but it turns the code into a mess and doesn't give a complete picture.\n\nHere's a simplified example of my code that processes a large dataset:\n\n
#include <vector>\n#include <algorithm>\n#include <iostream>\n\nvoid processData(const std::vector<int>& data) {\n    std::vector<int> result;\n    for (size_t i = 0; i < data.size(); ++i) {\n        if (data[i] % 2 == 0) {\n            result.push_back(data[i] * data[i]);\n        }\n    }\n    // Then complex calculations...\n    std::sort(result