Thursday, January 14, 2010

C++ Builder 2010 Optimizing C++ Compiler

I'm pleasantly surprised after giving C++ Builder 2010 a quick spin. It's much better at optimizing code than its predecessor CB2007 (I skipped CB2009 altogether as it was and still is completely broken).

CB2010 vs CB2007:

AnsiString test:
6938ms vs 6765ms

GcString test:
420ms vs 1734ms
(yes, that's 420ms, it's not a typo)

In the AnsiString test, things got just a bit slower (about 2% - nothing to worry about). But the big surprise here is my GcString test, which is over 400% FASTER!

Code for the test above (executed on Core2Duo 2.33GHz with TBBMM):

void __fastcall RunTest()
{

const
int TEST_COUNT = 10;
const
int TEST_SIZE = 10000;
const
int LOOP_COUNT = 1000;

{

// RefCounted String Test
AnsiString strings[TEST_SIZE];
for
(int i=0; i<TEST_SIZE; i++)
{

strings[i] = "test";
}


DWORD start = GetTickCount();
for
(int x=0; x<LOOP_COUNT; x++)
{

AnsiString temp;
for
(int j=0; j<TEST_COUNT; j++)
for
(int i=0; i<TEST_SIZE/2; i++)
{

temp = strings[i];
strings[i] = strings[TEST_SIZE-1-i];
strings[TEST_SIZE-1-i] = temp;
}
}

ShowMessage(IntToStr((int)GetTickCount() - (int)start));
}

{

// GcString Test
GcString strings[TEST_SIZE];
for
(int i=0; i<TEST_SIZE; i++)
{

strings[i] = "test";
}


DWORD start = GetTickCount();
for
(int x=0; x<LOOP_COUNT; x++)
{

GcString temp;
for
(int j=0; j<TEST_COUNT; j++)
for
(int i=0; i<TEST_SIZE/2; i++)
{

temp = strings[i];
strings[i] = strings[TEST_SIZE-1-i];
strings[TEST_SIZE-1-i] = temp;
}
}

ShowMessage(IntToStr((int)GetTickCount() - (int)start));
}
}


As you may have noticed, it is simply an array reversal test. And yes, the GcString version was 4 times faster even in CB2007. In CB2010, GcString is now a staggering 16.5 times faster than AnsiString!

No comments: