CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Benchmark my string class?

Threaded View

  1. #1
    Join Date
    Jan 2009

    Red face Benchmark my string class?

    A while ago someone mentioned that sometimes it's good to have a C point of view in a C++ forum and it got me wondering what would happen if I created a string class using some C string optimizations use that sSTL string don't use. So I wrote a minimal one to throw into one of my parsing engines and was surprised by the amount of speed I got out of it with very little optimization. It's not for every day string use, more for parsing and things that use lots of substrs, because this class does substr in O(1) instead of O(n). It's also not thread safe. I was just wondering if I couldn't get some of you to do a quick benchmark for me. Perhaps if the performance is good across a variety of platforms I'll implement the rest of the interface and put it on sourceforge.

    Just do
    g++ main.cpp -O3 -DNDEBUG
    on the directory, then an ./a.out. Then just post the bottom half of the output, this part:

    Benchmark           STD String  String      String Wins
    = operator char*    30000       1           Yes (3000000% faster)
    = operator string   120000      1           Yes (12000000% faster)
    Copy ctor           10000       1           Yes (1000000% faster)
    Copy ctor + append  200000      210000      No  (104% slower)
    Copy ctor with num  110000      1           Yes (11000000% faster)
    Ctor const char*    140000      170000      No  (121% slower)
    Ctor const char* n  90000       110000      No  (122% slower)
    Ctor empty          1           1           Equal
    Ctor n, c           90000       110000      No  (122% slower)
    Substr              210000      1           Yes (21000000% faster)
    Substr via ctor     220000      190000      Yes (115% faster)
    append char         820000      480000      Yes (170% faster)
    append char*        1680000     560000      Yes (300% faster)
    append string       1590000     1080000     Yes (147% faster)
    swap                1           1           Equal
    Obviously those huge percentages aren't accurate, that's a fault of the precision of the internal timer. My compiler seems to have a precision of millseconds for clock(), the 1s are just too fast to get a reading. I get more precise results on my mac.
    Attached Files Attached Files
    Last edited by ninja9578; February 15th, 2011 at 07:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)