Moin Leute,
Heut gibts mal was ganz kleines von mir. Hierbei handelt es sich um einen Commandprozessor, welcher dieselbe Funktion übernimmt, wie der allgemein bekannte Prozessor "OCMD", nur ist dieser ein Stück schneller, wie im Folgenden Speedtest belegt wird.
Vorweg: Wie erstellt man einen Befehl?
Diese Frage ist leicht zu beantworten. Ihr erstellt den Befehl nach folgendem Shema:
RGCMD:Befehlname(playerid,params[])
{
return 1;
}
Natürlich darf hierbei das #include rgcmd am Scriptanfang nicht fehlen.
Diesen Code könnt ihr nach Belieben iwo in eurem GM oder FS platzieren.
Darin könnt ihr nun wie gewohnt mit sscanf eure Params verwalten.
Soo nun zum Speedtest:
Bei 25 Durchläufen mit jeweils 100.000 Befehlsaufrufen komme ich auf folgendes Ergebnis:
ZitatAlles anzeigenSpoiler anzeigen [19:36:29] --- OCMD vs RGCMD vs BCMD (25 a 100000), TestCMD: /test Moin Leutz was macht ihr so?
[19:36:34] RGCMD 0642ms
[19:36:34] BCMD 1655ms
[19:36:34] OCMD 1975ms
[19:36:34] Gewinner Runde 1 -> RGCMD
[19:36:38] RGCMD 0639ms
[19:36:38] BCMD 1655ms
[19:36:38] OCMD 1959ms
[19:36:38] Gewinner Runde 2 -> RGCMD
[19:36:42] RGCMD 0645ms
[19:36:42] BCMD 1651ms
[19:36:42] OCMD 1965ms
[19:36:42] Gewinner Runde 3 -> RGCMD
[19:36:46] RGCMD 0644ms
[19:36:46] BCMD 1656ms
[19:36:46] OCMD 1980ms
[19:36:46] Gewinner Runde 4 -> RGCMD
[19:36:51] RGCMD 0644ms
[19:36:51] BCMD 1660ms
[19:36:51] OCMD 1964ms
[19:36:51] Gewinner Runde 5 -> RGCMD
[19:36:55] RGCMD 0646ms
[19:36:55] BCMD 1653ms
[19:36:55] OCMD 2025ms
[19:36:55] Gewinner Runde 6 -> RGCMD
[19:37:00] RGCMD 0691ms
[19:37:00] BCMD 1830ms
[19:37:00] OCMD 2032ms
[19:37:00] Gewinner Runde 7 -> RGCMD
[19:37:04] RGCMD 0659ms
[19:37:04] BCMD 1661ms
[19:37:04] OCMD 1979ms
[19:37:04] Gewinner Runde 8 -> RGCMD
[19:37:08] RGCMD 0653ms
[19:37:08] BCMD 1668ms
[19:37:08] OCMD 1964ms
[19:37:08] Gewinner Runde 9 -> RGCMD
[19:37:12] RGCMD 0651ms
[19:37:12] BCMD 1648ms
[19:37:12] OCMD 1958ms
[19:37:12] Gewinner Runde 10 -> RGCMD
[19:37:17] RGCMD 0655ms
[19:37:17] BCMD 1639ms
[19:37:17] OCMD 1971ms
[19:37:17] Gewinner Runde 11 -> RGCMD
[19:37:21] RGCMD 0646ms
[19:37:21] BCMD 1661ms
[19:37:21] OCMD 1976ms
[19:37:21] Gewinner Runde 12 -> RGCMD
[19:37:25] RGCMD 0647ms
[19:37:25] BCMD 1651ms
[19:37:25] OCMD 1979ms
[19:37:25] Gewinner Runde 13 -> RGCMD
[19:37:29] RGCMD 0647ms
[19:37:29] BCMD 1648ms
[19:37:29] OCMD 1971ms
[19:37:29] Gewinner Runde 14 -> RGCMD
[19:37:34] RGCMD 0640ms
[19:37:34] BCMD 1645ms
[19:37:34] OCMD 1966ms
[19:37:34] Gewinner Runde 15 -> RGCMD
[19:37:38] RGCMD 0653ms
[19:37:38] BCMD 1640ms
[19:37:38] OCMD 1985ms
[19:37:38] Gewinner Runde 16 -> RGCMD
[19:37:45] RGCMD 0649ms
[19:37:45] BCMD 1672ms
[19:37:45] OCMD 1969ms
[19:37:45] Gewinner Runde 17 -> RGCMD
[19:37:49] RGCMD 0662ms
[19:37:49] BCMD 1656ms
[19:37:49] OCMD 1965ms
[19:37:49] Gewinner Runde 18 -> RGCMD
[19:37:54] RGCMD 0638ms
[19:37:54] BCMD 1648ms
[19:37:54] OCMD 1974ms
[19:37:54] Gewinner Runde 19 -> RGCMD
[19:37:58] RGCMD 0640ms
[19:37:58] BCMD 1646ms
[19:37:58] OCMD 1966ms
[19:37:58] Gewinner Runde 20 -> RGCMD
[19:38:02] RGCMD 0647ms
[19:38:02] BCMD 1653ms
[19:38:02] OCMD 1967ms
[19:38:02] Gewinner Runde 21 -> RGCMD
[19:38:06] RGCMD 0639ms
[19:38:06] BCMD 1647ms
[19:38:06] OCMD 1973ms
[19:38:06] Gewinner Runde 22 -> RGCMD
[19:38:11] RGCMD 0649ms
[19:38:11] BCMD 1663ms
[19:38:11] OCMD 1971ms
[19:38:11] Gewinner Runde 23 -> RGCMD
[19:38:15] RGCMD 0650ms
[19:38:15] BCMD 1689ms
[19:38:15] OCMD 2124ms
[19:38:15] Gewinner Runde 24 -> RGCMD
[19:38:20] RGCMD 0714ms
[19:38:20] BCMD 1741ms
[19:38:20] OCMD 1968ms
[19:38:20] Gewinner Runde 25 -> RGCMD
[19:38:20] -------ERGEBNIS:------
[19:38:20] RGCMD 25/25 Runden gewonnen
[19:38:20] BCMD 0/25 Runden gewonnen
[19:38:20] OCMD 0/25 Runden gewonnen
Testcode:
Timing test
made by BlackAce
modified by RG
*/
#include a_samp
#define TEST_LOOPS 100000
#define TEST_CMD "/test Moin Leutz was macht ihr so?"
new result[3];
forward StartTest();
public StartTest() {
for(new i ; i < TEST_RUNS ; i++ )
{
new
tick2,
tick3,
tick1,
tick4;
tick1 = GetTickCount();
for(new j ; j < TEST_LOOPS ; j++)
{
RGOnPlayerCommandText(0,TEST_CMD);
}
tick2 = GetTickCount();
for(new j ; j < TEST_LOOPS ; j++)
{
BCMDOnPlayerCommandText(0,TEST_CMD);
}
tick3 = GetTickCount();
for(new j ; j < TEST_LOOPS ; j++)
{
OCMDOnPlayerCommandText(0,TEST_CMD);
}
tick4 = GetTickCount();
new
RGCMD = tick2 - tick1,
BCMD = tick3 - tick2,
OCMD = tick4 - tick3;
printf("RGCMD %04dms",RGCMD);
printf("BCMD %04dms",BCMD);
printf("OCMD %04dms",OCMD);
if(RGCMD < BCMD && RGCMD < OCMD)
result[0]++,printf("Gewinner Runde %d -> RGCMD",(i+1));
if( BCMD < RGCMD && BCMD < OCMD)
result[1]++,printf("Gewinner Runde %d -> BCMD",(i+1));
if( OCMD < RGCMD && OCMD < BCMD)
result[2]++,printf("Gewinner Runde %d -> OCMD",(i+1));
}
printf("-------ERGEBNIS:------");
printf("RGCMD %d/%d Runden gewonnen",result[0],TEST_RUNS);
printf("BCMD %d/%d Runden gewonnen",result[1],TEST_RUNS);
printf("OCMD %d/%d Runden gewonnen",result[2],TEST_RUNS);
return 1;
}
SetTimer("StartTest",1800,false);
return 1;
}
#define RGCMD:%0(%1) forward rgcmd_%0(%1);\
public rgcmd_%0(%1)
#define bcmd:%1(%2) forward bcmd_%1(%2); \
public bcmd_%1(%2)
#define ocmd:%1(%2) forward ocmd_%1(%2); \
public ocmd_%1(%2)
forward RGOnPlayerCommandText(playerid,cmdtext[]);
forward OCMDOnPlayerCommandText(playerid,cmdtext[]);
forward BCMDOnPlayerCommandText(playerid,cmdtext[]);
public RGOnPlayerCommandText(playerid,cmdtext[])
{
new cmd[32], pos = strfind(cmdtext," ",true);
strmid(cmd,cmdtext,1,pos);
for(new i = 0, len = strlen(cmd); i < len; i++)
{
switch(cmd[i])
{
case 'A': cmd[i] = 'a'; case 'B': cmd[i] = 'b'; case 'C': cmd[i] = 'c';
case 'D': cmd[i] = 'd'; case 'E': cmd[i] = 'e'; case 'F': cmd[i] = 'f';
case 'G': cmd[i] = 'g'; case 'h': cmd[i] = 'h'; case 'I': cmd[i] = 'i';
case 'J': cmd[i] = 'j'; case 'K': cmd[i] = 'k'; case 'L': cmd[i] = 'l';
case 'M': cmd[i] = 'm'; case 'N': cmd[i] = 'n'; case 'O': cmd[i] = 'o';
case 'P': cmd[i] = 'p'; case 'Q': cmd[i] = 'q'; case 'R': cmd[i] = 'r';
case 'S': cmd[i] = 's'; case 'T': cmd[i] = 't'; case 'U': cmd[i] = 'u';
case 'V': cmd[i] = 'v'; case 'W': cmd[i] = 'w'; case 'X': cmd[i] = 'x';
case 'Y': cmd[i] = 'y'; case 'Z': cmd[i] = 'z';
}
}
strins(cmd,"rgcmd_",0);
if(pos == -1)
{
if(CallLocalFunction(cmd,"ds",playerid, " ")) return 1;
strins(cmd,"/",0);
return CallLocalFunction("oldOnPlayerCMDText","ds",playerid,cmdtext);
}
new params1[64];
strmid(params1,cmdtext,pos+1,strlen(cmdtext));
if(CallLocalFunction(cmd,"ds",playerid, params1)) return 1;
return CallLocalFunction("oldOnPlayerCMDText","ds",playerid,cmdtext);
}
public BCMDOnPlayerCommandText(playerid,cmdtext[])
{
}
public OCMDOnPlayerCommandText(playerid,cmdtext[])
{
cmdtext[0]='_';
new ocmdStr[128],ocmdParams[128],bool:ocmdAffe,ocmdFu;
for(new i;i<128;i++)
{
if(cmdtext[i]=='\0')break;
if((cmdtext[i]==' ')&&(!ocmdAffe))
{
ocmdAffe=true;
continue;
}
if(!ocmdAffe)
{
cmdtext[i] = tolower(cmdtext[i]);
ocmdStr[i]=cmdtext[i];
}
else
{
ocmdParams[ocmdFu]=cmdtext[i];
ocmdFu++;
}
}
format(ocmdStr,128,"ocmd%s",ocmdStr);
if(!strlen(ocmdParams))format(ocmdParams,128," ");
if(CallLocalFunction(ocmdStr,"ds",playerid,ocmdParams))return 1;
cmdtext[0]='/';
return CallLocalFunction("oldOnPlayerCMDText","ds",playerid,cmdtext);
}
bcmd:test(playerid,params[])
{
return 1;
}
ocmd:test(playerid,params[])
{
return 1;
}
RGCMD:test(playerid,params[])
{
return 1;
}
Spezielles Danke an:
946ben, er hat mir gezeigt, dass ein switch schneller ist, als die "tolower" Funktion