How to measure speed of a command? - 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)
+--- Thread: How to measure speed of a command? (
/showthread.php?tid=628625)
How to measure speed of a command? -
faxxe - 12.02.2017
Ahoy
Currently i got 2 /get commands, the 1st one with strtok included, and the second one with sscanf.
I want to find out which one is faster and more efficient but i dont know if there is a way to measure that
I would be glad to receive help!
sscanf
Код:
if(strcmp(cmd, "/get", true) == 0)
{
if(IsPlayerAdmin(playerid))
{
new targetplayer;
if(sscanf(cmdtext[strlen("/get")+1], "u", targetplayer))
return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /get [playerid]");
if(!IsPlayerConnected(targetplayer))
return SendClientMessage(playerid, COLOR_WHITE, "SERVER: Player not connected");
if(playerid == targetplayer)
return SendClientMessage(playerid, COLOR_WHITE, "SERVER: You cannot get yourself!");
if(IsPlayerConnected(targetplayer))
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerInterior(targetplayer,GetPlayerInterior(playerid));
SetPlayerPos(targetplayer, x+1, y+1, z);
return 1;
}
}
else
{
return 0;
}
}
strtok
Код:
if(strcmp(cmd, "/get", true) == 0)
{
if(IsPlayerAdmin(playerid))
{
new tmp[20], targetplayer;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /get [playerid]");
targetplayer = strval(tmp);
if(!IsPlayerConnected(targetplayer))
return SendClientMessage(playerid, COLOR_WHITE, "SERVER: Player not connected");
if(playerid == targetplayer)
return SendClientMessage(playerid, COLOR_WHITE, "SERVER: You cannot get yourself!");
if(IsPlayerConnected(targetplayer))
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerInterior(targetplayer,GetPlayerInterior(playerid));
SetPlayerPos(targetplayer, x+1, y+1, z);
return 1;
}
}
else
{
return 0;
}
}
Re: How to measure speed of a command? -
RyderX - 12.02.2017
SSCANF would be more faster than strtok since it's more newest than strtok,
i require to use ZCMD, it will facilitate your command processing.