Boost logo

Boost :

From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2008-02-15 12:54:15

Giovanni Piero Deretta wrote:
> On Thu, Feb 14, 2008 at 6:50 PM, Phil Endecott
> <spam_from_boost_dev_at_[hidden]> wrote:
>> In each case, I've used the predicate with std::find_if. But if I
>> instead use C's strcspn() to do the whole job, I see a relative
>> performance for this example of 20. I find it depressing that the C++
>> code doesn't come close to that.
> Well, it is not really a fair comparison, the 'C' function is likely
> implemented in hand optimized assembler, (
> and for such a small function, humans are still better than compilers.
> So it isn't really C++ versus C. Also the C version is not generic at
> all.

Hi Giovanni,

I can't agree with that. There's no reason why the C++ implementation
couldn't be written in hand-optimised assembler too. Or it could
simply call the fast C function:

template <> const char* std::find(const char* first, const char* last,
char value) <const char*> {
   return ::memchr(first,value,last-first);

Specialisation allows C++ libraries to provide functions that are both
generic and optimised for special cases.

Anyway, rather than complaining I should be writing code. This week I
have been writing some UTF-8 encoding and decoding and
Unicode<->iso8859 conversion algorithms. They seem to be faster than
the libc implementations which is satisfying especially as I haven't
even started on the serious optimisations yet. This will be part of
the strings-tagged-with-character-sets stuff that I have described
before. Anyone interested?


Boost list run by bdawes at, gregod at, cpdaniel at, john at