SA-MP Forums Archive
Which is quicker? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Which is quicker? (/showthread.php?tid=268617)



Which is quicker? - beckzy - 13.07.2011

Using arrays or using SetPVarInt/GetPVarInt etc to store player data?


Re: Which is quicker? - RyDeR` - 13.07.2011

Using arrays.

You may have a look at this topic: https://sampforum.blast.hk/showthread.php?tid=268499


Re: Which is quicker? - beckzy - 13.07.2011

Has anybody done speed tests to see the difference? Are PVars much slower than variables or is there not much of a difference?


Re: Which is quicker? - RyDeR` - 13.07.2011

I did a speedtest a while ago. PVars are actually slower than normal variables.


Re: Which is quicker? - beckzy - 13.07.2011

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
I did a speedtest a while ago. PVars are actually slower than normal variables.
Quite a lot slower or not much?


Re: Which is quicker? - RyDeR` - 13.07.2011

Quite a lot. Here's speedtest if you're still not sure:
Код:
» pVars: 1000000 times in 6232 ms.
» Normal Array: 1000000 times in 1906 ms.

» pVars: 1000000 times in 6233 ms.
» Normal Array: 1000000 times in 1907 ms.

» pVars: 1000000 times in 6233 ms.
» Normal Array: 1000000 times in 1908 ms.
pawn Код:
new
    g_PlayerVar[MAX_PLAYERS][2]
;

if(!strcmp(cmdtext, "/speedtest", true))
{
    new
        str[64],
        startTick,
        i
    ;
    for(i = 0, startTick = GetTickCount(); i < 10000000; ++i)
    {
        SetPVarInt(playerid, "pv_PlayerVar1", GetPVarInt(playerid, "pv_PlayerVar1") + i);
        SetPVarInt(playerid, "pv_PlayerVar2", GetPVarInt(playerid, "pv_PlayerVar2") + i);
    }
    format(str, sizeof(str), "» pVars: 1000000 times in %d ms.", GetTickCount() - startTick);
    SendClientMessage(playerid, -1, str);
       
    for(i = 0, startTick = GetTickCount(); i < 10000000; ++i)
    {
        g_PlayerVar[playerid][0] += i;
        g_PlayerVar[playerid][1] += i;
    }
    format(str, sizeof(str), "» Normal Array: 1000000 times in %d ms.", GetTickCount() - startTick);
    SendClientMessage(playerid, -1, str);  
    return 1;
}