20.08.2011, 11:25
Today I have implemented a name getting method, which is faster than GetPlayerName.
What do you think? Is it significant?
What do you think? Is it significant?
Quote:
[join] Colonel_Vincent has joined the server (0:127.0.0.1) Timer engaged for player 0 GetPlayerName time, for 100 000 000 run: 31993 ms PName time, for 100 000 000 run: 20775 ms GetPlayerName: 'Colonel_Vincent`[15] PName: 'Colonel_Vincent`[15] |
pawn Code:
new playernames[MAX_PLAYERS][MAX_PLAYER_NAME];
#define PName(%1) playernames[(%1)]
public myhook_SetPlayerName(playerid, const name[])
{
new r = SetPlayerName(playerid, name);
if (r) format(playernames[playerid], MAX_PLAYER_NAME, "%s", name);
return 1;
}
#if defined _ALS_SetPlayerName
#undef SetPlayerName
#else
#define _ALS_SetPlayerName
#endif
#define SetPlayerName myhook_SetPlayerName
forward myhook_SetPlayerName(playerid, const name[]);
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, playernames[playerid], MAX_PLAYER_NAME);
SetTimerEx("tmr", 2000, 0, "d", playerid);
printf("Timer engaged for player %d", playerid);
return 1;
}
forward tmr(playerid);
public tmr(playerid)
{
new store_here[MAX_PLAYER_NAME], tmp[MAX_PLAYER_NAME];
new tick_generic = GetTickCount();
for (new i = 0; i < 100_000_000; i++) GetPlayerName(playerid, store_here, MAX_PLAYER_NAME);
new generic_time = GetTickCount() - tick_generic;
strcat(tmp, store_here);
new tick_pname = GetTickCount();
for (new i = 0; i < 100_000_000; i++) store_here = PName(playerid);
new pname_time = GetTickCount() - tick_pname;
printf("GetPlayerName time, for 100 000 000 run: %d ms", generic_time);
printf("PName time, for 100 000 000 run: %d ms", pname_time);
printf("GetPlayerName: '%s`[%d] PName: '%s`[%d]", tmp, strlen(tmp), store_here, strlen(store_here));
return 1;
}