Menu

#167 Speed issue with conditional asserts

1.12.0
open
nobody
5
2006-08-11
2006-08-11
pan
No

I had a test like this:

for(int i = 0; i < arrsize; i++) {
x[i] = i;
}
for(int i = 0; i < arrsize; i++) {
CPPUNIT_ASSERT(x[i] == i);
}

and noticed it was REALLY TOO SLOW.

I figured out what's the point: CPPUNIT_ASSERT always
calls CPPUNIT_NS::Asserter::failIf passing two
std::string as parameters, so the compiler wasn't
optimizing the string construction (and constructing
two strings everytime).

IMHO this can be solved in 2 ways:

1) changing failIf parameters to const char *

2) modifying CPPUNIT_ASSERT this way:

#define CPPUNIT_ASSERT(condition) \ { if (!condition) \ CPPUNIT_NS::Asserter::fail( \ CPPUNIT_NS::Message("assertion failed", \ "Expression: " #condition), \ CPPUNIT_SOURCELINE() \ ); \ }

I have tested the latter solution and it's working
(and running fast) in my case.

Thank you in advance

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.