[Off] Desafio: strfind rбpido
#2

Jб que ninguйm quis, aqui minha funзгo.

й duas vezes mais rбpido no ignorecase:

fstrfind

pawn Код:
new
    i_loop@find,
    j_loop@find,
    p_loop@find;

fstrfind( text[] , pattern[] , {bool,_}: ignorecase = false, pos = -1)
{
    if(!ignorecase)
        return strfind( text , pattern, ignorecase, pos);


    j_loop@find = strlen(pattern)-1;

    for(i_loop@find = strlen(text)-1 ; i_loop@find > pos ; --i_loop@find) {

        calcular:

        p_loop@find = (text[i_loop@find] ^ pattern[j_loop@find]);

        if(!((32 ^ p_loop@find) & p_loop@find)) {

            if(!j_loop@find) return i_loop@find;

            i_loop@find--;
            j_loop@find--;

            if( ( ( ~i_loop@find ) ) ) {
                goto calcular;
            }

        }
        else {
            j_loop@find = strlen(pattern) - 1 ;
        }
    }
    return -1;
}

Depende do modo de uso:

pawn Код:
#define CONT GetTickCount()

new C = CONT;
for(new i; i != 10000; i++) {
    fstrfind("testa teste testu testi testo", "testu", true);
    fstrfind("testa teste testu testi strFind", "strFind", true);
    fstrfind("testa teste testu testi strFind", "testa", true);

    fstrfind("testa teste testu testi testo", "testu", false);
    fstrfind("testa teste testu testi strFind", "strFind", false);
    fstrfind("testa teste testu testi strFind", "testa", false);
}
C = CONT - C;

new T = CONT;
for(new i; i != 10000; i++)  {

    strfind("testa teste testu testi testo", "testu", true);
    strfind("testa teste testu testi strFind", "strFind", true);
    strfind("testa teste testu testi strFind", "testa", true);

    strfind("testa teste testu testi testo", "testu", false);
    strfind("testa teste testu testi strFind", "strFind", false);
    strfind("testa teste testu testi strFind", "testa", false);


}
T = CONT - T;

printf("%d x %d", C , T );
Reply


Messages In This Thread
Desafio: strfind rбpido - by ipsBruno - 08.10.2013, 18:52
Re: Desafio: strfind rбpido - by ipsBruno - 08.10.2013, 20:04
Re: Desafio: strfind rбpido - by PT - 08.10.2013, 20:42
Re: Desafio: strfind rбpido - by SkullFire - 08.10.2013, 20:53
Re: Desafio: strfind rбpido - by Juniiro3 - 08.10.2013, 21:19
Re: Desafio: strfind rбpido - by RuanRider - 08.10.2013, 21:35
Re: Desafio: strfind rбpido - by PT - 08.10.2013, 21:40
Re: Desafio: strfind rбpido - by RuanRider - 08.10.2013, 21:41
Re: Desafio: strfind rбpido - by ipsBruno - 08.10.2013, 21:51
Re: Desafio: strfind rбpido - by WLSF - 09.10.2013, 00:28

Forum Jump:


Users browsing this thread: 3 Guest(s)