Click here to Skip to main content
15,881,852 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGeneric Specialized Template Definitions Pin
Skippums22-Jun-09 8:42
Skippums22-Jun-09 8:42 
AnswerRe: Generic Specialized Template Definitions Pin
Stuart Dootson22-Jun-09 9:31
professionalStuart Dootson22-Jun-09 9:31 
GeneralRe: Generic Specialized Template Definitions Pin
Skippums23-Jun-09 3:22
Skippums23-Jun-09 3:22 
GeneralRe: Generic Specialized Template Definitions Pin
Stuart Dootson23-Jun-09 3:36
professionalStuart Dootson23-Jun-09 3:36 
AnswerRe: Generic Specialized Template Definitions Pin
Nemanja Trifunovic22-Jun-09 9:34
Nemanja Trifunovic22-Jun-09 9:34 
GeneralRe: Generic Specialized Template Definitions Pin
Skippums22-Jun-09 9:52
Skippums22-Jun-09 9:52 
GeneralRe: Generic Specialized Template Definitions Pin
Nemanja Trifunovic22-Jun-09 10:04
Nemanja Trifunovic22-Jun-09 10:04 
QuestionPerformance problem with my FindOneOf function [modified] Pin
Ivan Ivanov 8322-Jun-09 4:09
Ivan Ivanov 8322-Jun-09 4:09 
Hi All

I'm developing my own CString class. With the idea to make it "much" faster than the standard CString, easily upgradeable, and to include into it some non-standard parsing functions I often use in my work, those will be much better to be part of the CFString object itself, instead of being separate functions.
And in deed I have some noticeable achievements for the basic functions my CFString uses:

My copy() is 35% faster then strcpy()!

My lengh() is 30% faster than strlen().
BUT note that the optimizer often pre-calculates strlen() calls and replaces them with respective numbers!
For example int i = strlen("abc") will eventually generate mov EAX, 3 instaed of generating the asm code of strlen() itself, that happens for hardcoded strings! so in the cases when strlen() isn't replaced by a number, my function is 30% faster

My compare() is 20% faster than strcmp().

I used the inline assembly option of the Visual C++ compiler, the "__asm" command to achieve this.

I also developed an equalizing mechanism, so when I write str1 = str2 the "operator =" actually doesn't copy the data from str2 to str1
the copy occurs ONLY in specific cases when it's needed.
And that mechanism provides about 35 - 40% faster equalizing betweend CFString objects in comparison to the CString equalizing!

So far so good! But in the case with FindOneOf the standard CString beated me badly! CString::FindOneOf is almost twise faster than my CFString::FindOneOf, and my FindOneOf IS written in assembly too. I did everithing I could to tweak it up, but I only reduced the time from 33000ms to 28000ms and CString::FindOneOf does the job for 18000ms, and my function suppose to be faster, now I'll be happy just to equal the score of CString::FindOneOf!
This is the test code I use:
CString/CFString str1("abcdefghijklmnoprs0987654321");

int start = GetTickCount();
for(int pos = 0; pos; 100000000; pos++)
{
    index = 0;
    index = str1.FindOneOf("1234567890");
}
int time = GetTickCount() - start;

CString strTime;
strTime.Format("%d, %d", time, index);
m_editResult.SetWindowText(strTime); //this is the CEdit object I use for output

I looked at the disassembly of the CString::FindOneOf but couldn't find a single loop, I didn't understan anything! there are a lot of stack operations (PUSH POP) a lot of CALLs and they suppose to be slow, I don't have any idea how can this function beat mine!!!
This is the algorithm I use written in C, although it's written in assembly and I believe optimised in the actual function:
    const char* pstrTBuffer = m_pstrBuffer; //the actual string
const char* pstrTSeek   = pstrSeek; //the charset
do
{
    while(*pstrTSeek)
    {
        if(*pstrTBuffer == *pstrTSeek++)
        {
            return pstrTBuffer - m_pstrBuffer;
        }
    }
    pstrTSeek = pstrSeek;
}
while(*++pstrTBuffer);
return -1;

In case the code isn't clear enough:
The idea is as simple as possible, compare each character in the main string m_pstrBuffer with each character in the charset pstrSeek
if there is a match return its index if not return -1

I assumed that the problem isn't in my coding technique, it must be generally in the algorithm I use!!!
Does somebody know a better algorithm to implement FindOneOf??? Smile | :)
I will appreciate any help - thank you!!! Smile | :)

Sorry for the prolonged question, but I wanted to be as clear as I can in my description.

modified on Monday, June 22, 2009 10:20 AM

AnswerRe: Performance problem with my FindOneOf function Pin
Stuart Dootson22-Jun-09 8:46
professionalStuart Dootson22-Jun-09 8:46 
GeneralRe: Performance problem with my FindOneOf function Pin
Ivan Ivanov 8322-Jun-09 22:30
Ivan Ivanov 8322-Jun-09 22:30 
GeneralRe: Performance problem with my FindOneOf function Pin
Stuart Dootson22-Jun-09 22:48
professionalStuart Dootson22-Jun-09 22:48 
GeneralRe: Performance problem with my FindOneOf function Pin
Ivan Ivanov 8323-Jun-09 0:32
Ivan Ivanov 8323-Jun-09 0:32 
GeneralRe: Performance problem with my FindOneOf function Pin
Stuart Dootson23-Jun-09 0:41
professionalStuart Dootson23-Jun-09 0:41 
GeneralRe: Performance problem with my FindOneOf function Pin
Ivan Ivanov 8323-Jun-09 4:17
Ivan Ivanov 8323-Jun-09 4:17 
GeneralRe: Performance problem with my FindOneOf function Pin
Ivan Ivanov 8324-Jun-09 1:11
Ivan Ivanov 8324-Jun-09 1:11 
AnswerRe: Performance problem with my FindOneOf function Pin
Skippums22-Jun-09 9:02
Skippums22-Jun-09 9:02 
GeneralRe: Performance problem with my FindOneOf function Pin
Stuart Dootson22-Jun-09 9:34
professionalStuart Dootson22-Jun-09 9:34 
GeneralRe: Performance problem with my FindOneOf function Pin
Ivan Ivanov 8322-Jun-09 11:28
Ivan Ivanov 8322-Jun-09 11:28 
AnswerRe: Performance problem with my FindOneOf function Pin
Roger Stoltz22-Jun-09 9:22
Roger Stoltz22-Jun-09 9:22 
GeneralRe: Performance problem with my FindOneOf function Pin
Ivan Ivanov 8322-Jun-09 10:59
Ivan Ivanov 8322-Jun-09 10:59 
GeneralRe: Performance problem with my FindOneOf function Pin
Roger Stoltz22-Jun-09 21:39
Roger Stoltz22-Jun-09 21:39 
GeneralRe: Performance problem with my FindOneOf function [modified] Pin
Ivan Ivanov 8324-Jun-09 1:45
Ivan Ivanov 8324-Jun-09 1:45 
GeneralRe: Performance problem with my FindOneOf function Pin
Roger Stoltz24-Jun-09 4:16
Roger Stoltz24-Jun-09 4:16 
GeneralRe: Performance problem with my FindOneOf function [modified] Pin
Ivan Ivanov 8325-Jun-09 1:25
Ivan Ivanov 8325-Jun-09 1:25 
QuestionXMLHTTP post failed with status code 415 Pin
Ash_VCPP22-Jun-09 3:47
Ash_VCPP22-Jun-09 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.