[Tutorial] Pequenas Otimizaзхes
#1

Introduзгo:

Oi galera hoje vou postar alguns cуdigos relacionados a testes de velocidade.

Sгo cуdigos para vocк mesmo usar em seu pc e decidir qual й melhor ou pior.

Nгo й bem um Tutorial,atй porque nгo explico nada,apenas й 'Dicas' de pequenas otimizaзхes que vocк pode fazer.

Nota:
Espaзos nгo Otimizam Nada
return Funcao(playerid) em um comando tambйm nгo otimiza nada
! e == 0 e == false sгo a mesma coisa

Cуdigos:

Vou colocar o mбximo de cуdigos possнvel,execute-o em seu pc e veja qual й o melhor


While x For Loop

pawn Code:
#include <a_samp>


#define maxloop     (10000000)   //loops para teste

public OnFilterScriptInit()
{
    //==========================================================================

    new
        dCount = GetTickCount(),array,i;

    while (i < maxloop)
    {
        i++;
        array++;
    }

    printf("[While] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - dCount));

    //==========================================================================

    new
        bCount = GetTickCount(),arrei,a;
       
    for(a = 0; a < maxloop; a++)
    {
        arrei++;
    }
    printf("[For] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - bCount));

    //==========================================================================
    return true;
}
RESULTADO: For Mais rбpido

Code:
[13:21:56] [While] Functions: 10000000 - Temp: 486
[13:21:57] [For] Functions: 10000000 - Temp: 388
Static x New

pawn Code:
#include <a_samp>


#define maxloop     (1000000)   //loops para teste

public OnFilterScriptInit()
{
    //==========================================================================

    new
        dCount = GetTickCount();

    for(new i; i < maxloop; ++i)
    {
        static array;
    }

    printf("[Static] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - dCount));

    //==========================================================================

    new
        bCount = GetTickCount();
    for(new i; i < maxloop; ++i)
    {
        new array;
    }
    printf("[New] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - bCount));

    //==========================================================================
    return true;
}
RESULTADO: Static mais rбpido

Code:
[13:23:07] [Static] Functions: 1000000 - Temp: 24
[13:23:07] [New] Functions: 1000000 - Temp: 43
Max_Players x GetMaxPlayers
pawn Code:
#include <a_samp>


#define maxloop     (100000)   //loops para teste

public OnFilterScriptInit()
{
    //==========================================================================

    new
        dCount = GetTickCount();

    for(new i; i < maxloop; ++i)
    {
        for(new p; p < MAX_PLAYERS; p++)
        {
        }
    }

    printf("[MaxPlayers] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - dCount));

    //==========================================================================

    new
        bCount = GetTickCount();
    for(new i; i < maxloop; ++i)
    {
        for(new p; p < GetMaxPlayers(); p++)
        {
        }
    }
    printf("[GetMaxPlayer] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - bCount));

    //==========================================================================
    return true;
}
RESULTADO: Max_Players mais rбpido,claro

Code:
[13:26:21] [MaxPlayers] Functions: 100000 - Temp: 1064
[13:26:23] [GetMaxPlayer] Functions: 100000 - Temp: 2255
Defines x Stocks

pawn Code:
stock GetSAMP() return 10;
#define GetSAMP2 10

#include <a_samp>


#define maxloop     (100000)   //loops para teste

public OnFilterScriptInit()
{
    //==========================================================================

    new
        dCount = GetTickCount();

    for(new i; i < maxloop; ++i)
    {
        printf("Is %d",GetSAMP2);
    }

    printf("[Defines] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - dCount));

    //==========================================================================

    new
        bCount = GetTickCount();
    for(new i; i < maxloop; ++i)
    {
        printf("Is %d",GetSAMP());
    }
    printf("[Stocks] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - bCount));

    //==========================================================================
    return true;
}
RESULTADO: Defines,sempre que possнvel use-as

Code:
[13:30:04] [Defines] Functions: 100000 - Temp: 8534
[13:30:55] [Stocks] Functions: 100000 - Temp: 10971
I++ x ++I

pawn Code:
#include <a_samp>


#define maxloop     (100000000)   //loops para teste

public OnFilterScriptInit()
{
    //==========================================================================

    new
        dCount = GetTickCount();

    for(new i; i < maxloop; ++i)
    {
    }

    printf("[++i] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - dCount));

    //==========================================================================

    new
        bCount = GetTickCount();
    for(new i; i < maxloop; i++)
    {
    }
    printf("[i++] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - bCount));

    //==========================================================================
    return true;
}
RESULTADO: ++i й pouco mais otimizado

Code:
[13:33:24] [++i] Functions: 100000000 - Temp: 2129
[13:33:26] [i++] Functions: 100000000 - Temp: 2147
Strlen x Eos

pawn Code:
#include <a_samp>


#define maxloop     (100000000)   //loops para teste

static string[64] = "Oi isto й um teste haha";
public OnFilterScriptInit()
{
    //==========================================================================

    new
        dCount = GetTickCount();

    for(new i; i < maxloop; ++i)
    {
        if(string[10] != '\0')
        {
        }
    }

    printf("[Eos] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - dCount));

    //==========================================================================

    new
        bCount = GetTickCount();
    for(new i; i < maxloop; i++)
    {
        if(strlen(string) > 10)
        {
        }
    }
    printf("[Strlen] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - bCount));

    //==========================================================================
    return true;
}
RESULTADO: Usando End Of String com Condicional й muito mais rбpido
Code:
[13:46:14] [Eos] Functions: 100000000 - Temp: 4084
[13:46:23] [Strlen] Functions: 100000000 - Temp: 9799
Strins x Format

pawn Code:
#include <a_samp>


#define maxloop     (100000)   //loops para teste

static stringformat[64] = "Oi isto й um teste haha";
static stringstrins[64] = "Oi isto й um teste haha";
public OnFilterScriptInit()
{
    //==========================================================================

    new
        dCount = GetTickCount();

    for(new i; i < maxloop; ++i)
    {
        format(stringformat,64,"%s,oi",stringformat);
    }

    printf("[Format] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - dCount));

    //==========================================================================

    new
        bCount = GetTickCount();
    for(new i; i < maxloop; i++)
    {
        strins(stringstrins,",oi",strlen(stringstrins),sizeof stringstrins);
    }
    printf("[Strins] Functions: %d - Temp: %d",maxloop,(GetTickCount()  - bCount));
    //==========================================================================
    printf(stringstrins);
    printf(stringformat);
    return true;
}

RESULTADO: Usando Strins й bem mais otimizado,sempre use quando puder

Code:
[13:44:24] [Format] Functions: 100000 - Temp: 61
[13:44:24] [Strins] Functions: 100000 - Temp: 28
Como podem ver otimizaзгo em pawn existe,apesar de pawn nгo ser nada otimizado.
Porйm sempre tente fazer seu melhor,por que pawn jб й uma merda,agora se deixar mais merda ainda fode tudo.

Atй semana que vem,vou sair por um tempo,vгo postando seus testes e dicas para testes.

Atй mais.

Valeu
Reply


Messages In This Thread
Pequenas Otimizaзхes - by ipsBruno - 08.01.2011, 14:48
Re: Pequenas Otimizaзхes - by Ricop522 - 08.01.2011, 15:07
Re: Pequenas Otimizaзхes - by LuaN_ - 08.01.2011, 15:09
Re: Pequenas Otimizaзхes - by zSuYaNw - 08.01.2011, 15:19
Re: Pequenas Otimizaзхes - by [FeK]Knife - 08.01.2011, 15:20
Respuesta: Pequenas Otimizaзхes - by ipsBruno - 08.01.2011, 15:32
Re: Pequenas Otimizaзхes - by TiagoPS - 08.01.2011, 15:33
Re: Pequenas Otimizaзхes - by Ricop522 - 08.01.2011, 15:41
Re: Pequenas Otimizaзхes - by [L3th4l] - 09.01.2011, 18:36
Re: Pequenas Otimizaзхes - by CyNiC - 09.01.2011, 20:03
Re: Pequenas Otimizaзхes - by [L3th4l] - 09.01.2011, 22:00
Re: Pequenas Otimizaзхes - by MrDeath537 - 10.01.2011, 23:08
Re: Pequenas Otimizaзхes - by Katros - 11.01.2011, 11:55
Re: Pequenas Otimizaзхes - by syslogg - 13.01.2011, 01:43
Re: Pequenas Otimizaзхes - by frenetico - 15.01.2011, 02:56
Re: Pequenas Otimizaзхes - by zSuYaNw - 15.01.2011, 03:03
Re: Pequenas Otimizaзхes - by Coe1 - 02.12.2018, 12:12
Re: Pequenas Otimizaзхes - by Ermanhaut - 02.12.2018, 12:45
Re: Pequenas Otimizaзхes - by Felpz - 02.12.2018, 16:14

Forum Jump:


Users browsing this thread: 2 Guest(s)