some suggestions about optimization

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Shaeto
Posts: 147
Joined: Tue, 2009-01-20, 17:50
Location: CA, USA
Contact:

some suggestions about optimization

#1 Post by Shaeto »

some time ago i sat and read assoc.cc :)

i found several similar places with strange constructions:
for example in very important function ASC_findAcceptedPresentationContextID
----------------------------------------
while (pc && !found)
{
found = (strcmp(pc->abstractSyntax, abstractSyntax) == 0);
found &= (pc->result == ASC_P_ACCEPTANCE);
found &= ((strcmp(pc->acceptedTransferSyntax, UID_LittleEndianExplicitTransferSyntax) == 0) ||
(strcmp(pc->acceptedTransferSyntax, UID_BigEndianExplicitTransferSyntax) == 0));
if (!found) pc = (DUL_PRESENTATIONCONTEXT*) LST_Next(l);
}
-----------------------------------------

first, &= is bitwise operator, it will work for OFBool - agree, but it degrades performance of assoc functions.

every iteration will run 3 strcmp and 1 "==" but it is absolutely unnecessary!

mb better to rewrite it as:

{
found = (strcmp(pc->abstractSyntax, abstractSyntax) == 0) &&
(pc->result == ASC_P_ACCEPTANCE) && ((strcmp(pc->acceptedTransferSyntax, UID_LittleEndianExplicitTransferSyntax) == 0) || (strcmp(pc->acceptedTransferSyntax, UID_BigEndianExplicitTransferSyntax) == 0));

if (!found) pc = (DUL_PRESENTATIONCONTEXT*) LST_Next(l);
}

in this case we'll run only "true" statements and will stop right after first "false" found. most of iterations will execute only first (strcmp(pc->abstractSyntax, abstractSyntax) == 0)

strcmp is VERY expensive for cpu :)

thanks!

Michael Onken
DCMTK Developer
Posts: 2055
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: some suggestions about optimization

#2 Post by Michael Onken »

Hi Shaeto,
Shaeto wrote:some time ago i sat and read assoc.cc :)
Well, always a source for mysterious old code... -- We are happy that you take time to check through this jungle :-)
i found several similar places with strange constructions:
for example in very important function ASC_findAcceptedPresentationContextID
[..]
mb better to rewrite it as:

{
found = (strcmp(pc->abstractSyntax, abstractSyntax) == 0) &&
(pc->result == ASC_P_ACCEPTANCE) && ((strcmp(pc->acceptedTransferSyntax, UID_LittleEndianExplicitTransferSyntax) == 0) || (strcmp(pc->acceptedTransferSyntax, UID_BigEndianExplicitTransferSyntax) == 0));

if (!found) pc = (DUL_PRESENTATIONCONTEXT*) LST_Next(l);
}
Good point! I changed the code according to your proposal. Thanks for the suggestion, I hope I changed all occurences.

Best re

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests