pee kay pee kay - 1 year ago 132
C++ Question

High performance low latency C++ custom string class

My goal is to find the fastest C++ library for casting int to string, vice versa, and parsing.

Anyone that has experimented with performance of C++ will quickly realize that the string class of STL has terrible performance compared to say STL int arithmetic operations.

Some sample benchmarks from my 3.3 GHz Intel, GCC, CentOS 5.5 machine:

memcpy 0.004000 microsec/op
atoi 0.025000 microsec/op
atof 0.133000 microsec/op
strtod 0.133000 microsec/op
atof 0.135108 microsec/op
(char) uchar 0.001801 microsec/op
(char) ushort 0.001801 microsec/op
cache accs 0.010505 microsec/op
maplookup 0.128534 microsec/op
add_int 0.002456 microsec/op

You can quickly see that string operations will become a bottleneck for any high speed messaging applications.

I have located other libs for high performance strings (listed), but I am writing hoping someone has had similar difficulty and has reached some solution, possibly including writing their own string class.

Answer Source
int castString( const char * str )
    int val = 0;
    while( *str ) {
        val = val*10 + (*str++ - '0');
    return val;

This is very fast

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download