Way is this so slow?

Hello I made this simple search function and when giving it a big amount of data.
It takes forever to complete am talking between 6-7 digit sized buffer.

Anyone got a tip on how I can do this better?
Thanks to anyone how can take the time to answer my noobish question.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void SearchData(wstring wBuffer)
{
    const string FirstParam = "WetCode";
    const wstring wFirstParam = L"WetCode";
    string strBuffer;
    strBuffer.assign(wBuffer.begin(), wBuffer.end());
    string MatchFound = "";
    size_t PosFound = 0;
    size_t Secpos = 0;
    // Locate first ocurence

    while (PosFound != wstring::npos)
    {
        if (PosFound == wstring::npos)
        {
            break; // Noting more to be found.
        }
        // Search
        if (wBuffer.find(wFirstParam, PosFound) != string::npos)
        {
            for (;wBuffer.at(Secpos) < wBuffer.length();Secpos++)
            {
                if (Secpos < 46)
                {
                    break;
                }
            }
            cout << "Found: " << strBuffer.substr(PosFound, Secpos) << endl;cin.get();
        }
        Secpos = 0;
        PosFound++;
    }
}
Last edited on
> how I can do this better?

Use the Boyer–Moore algorithm.
http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm
What is that for loop at lines 17-22 supposed to be accomplishing?
Well, an line 1 you're copying the whole buffer. On line 5 you're copying the whole buffer again.

On line 12 you have an 'if' that's completely useless.

On line 16 you're searching the 'wFirstParam' but you don't care where it is.

I have really no idea what you're trying to do on line 17.

if you don't get to line 21, you will have at least 4294967295 cycles
Line 21 will be reached either at the first time or not at all
Wow this is realy great stuff, but it wont meet my need proporly since i will be needing to sort for strings that are not the same but simlar to one and other.. WetCode was just a test string am sorry i wasent clearer on the mather.
Cheers
Yes I was laughing like hell when I woke up this is funny stuff :p
HeHe forgot to change the post I got it working now :p
Anyways I would like to know of any good comparing algorithms to see if they hold a set of values but they are not the same.
Last edited on
Topic archived. No new replies allowed.