0

I have an application that was strictly using Boost for regex. I upgraded to g++4.9 and switched the some, but not all, of the code over to using the built-in regex functions (straight forward change). After switching, I tried using valgrind's --callgrind functionality to profile the application. But it's extremely slow. Although it's relative to my application, it went from around 30 iterations per second to less than 1 per second. I've tested with/without valgrind running to ensure it's not the application itself. I've also tested with the Boost implementation and had no issue.

I've tested with valgrind 3.10.0 and 3.10.1 and both exhibit the same behavior.

Edit: A simplified version of the function I replaced. With the similarity of Boost and C++ syntax, the two functions are essentially identical except for the namespaces (Boost:: v. std::).

void func() {
    ifstream fin;
    fin.open("file1");

    string check;
    stringstream ss (stringstream::in | stringstream::out);
    ss << "Some complicated regex";
    getline(ss, check);
    regex replacementRecord(check);

    smatch results;

    regex pattern1("thing1");

    while(!fin.eof()) {
        string line;
        getline(fin, line);
        // skip blank or newline
        if (line == "" || line == "\n") {
            continue;
        }

        // Check for these important patterns first
        if (regex_search(line, results, pattern1)) {
            // do stuff
            continue;
        } 

        // No important patters, look for this replacementRecod
        if(regex_search(line, results, replacementRecord)) {
            string prefix(results[1].first, results[1].second);
            // do stuff
        }
        else {
            // do other stuff
        }
    }
    fin.close();
}
shifty_28
  • 1
  • 2
  • 2
    You can use the `nulgrind` tool (instead of `callgrind`), to check if the issue is in Valgrind's CPU virtualization or actually in callgrind itself. – DevSolar Jun 12 '15 at 13:46
  • Are you compiling both with full optimizations? Specifically _check_ whether the standard-library version uses checked iterators! – sehe Jun 12 '15 at 14:59
  • Good thinking. I used `nulgrind`(`--tool=none`) and it was faster but not as fast as it should be. – shifty_28 Jun 12 '15 at 16:06
  • 1
    Maybe just add a SSCCE. So we can dig out the information you're still not giving. – sehe Jun 12 '15 at 18:49
  • Sorry for the lack of explanation on my side. Perhaps the example code will help. – shifty_28 Jun 19 '15 at 14:22

0 Answers0