Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High performance low latency C++ custom string class

Tags:

c++

string

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.

  • http://bstring.sourceforge.net/
  • http://code.google.com/p/stringencoders/
  • http://www.and.org/vstr/comparison
  • http://www.boost.org/doc/libs/1_46_1/doc/html/string_algo.html
like image 735
Chuck Norrris Avatar asked Apr 04 '11 16:04

Chuck Norrris


1 Answers

You didn't provide much information about your servers, but have a look at these libraries from AMD and Intel:

AMD String Library

Intel Integrated Performance Primitives

Both use SSE extensions to speed up string operations.

As far as I can see, they have no atoi(), but you could use the libraries to locate the decimals in the input. Given the string location and length it should be trivial to write a conversion using SSE intrinsics.

like image 66
Mackie Messer Avatar answered Oct 02 '22 01:10

Mackie Messer