Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

std::remove_if GCC implementation isn't efficient?

$
0
0

From another question here there seems to be evidence, that GCC's implementation of std::remove_if doesn't provide equally efficiency compared to the following implementation:

'raw homebrew' solution:

static char str1[100] = "str,, ing";size_t size = sizeof(str1)/sizeof(str1[0]);int bad = 0;int cur = 0;while (str1[cur] != '\0') {    if (bad < cur && !ispunct(str1[cur]) && !isspace(str1[cur])) {        str1[bad] = str1[cur];    }    if (ispunct(str1[cur]) || isspace(str1[cur])) {        cur++;    } else {        cur++;        bad++;    }}str1[bad] = '\0';

Timing outputs:

0.106860

Sample benchmarking code for std::remove_if for a solution of the same problem:

bool is_char_category_in_question(const char& c) {    return std::ispunct(c) || std::isspace(c);}std::remove_if(&str1[0], &str1[size-1], is_char_category_in_question);

Timing outputs:

1.986838

Check and get actual runtime results for the code running the ideone links above please (giving the full codes here would obscure the question!).

Given the provided execution time results (from the samples), these seem to confirm the first implementation is having much better performance.

Can anyone tell reasons, why the std::remove_if() algorithm doesn't (or can't) provide a similarly efficient solution for the given problem?


Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>