31.12.2012, 08:05
I want to know which method is better to send a formatted message, ****** method or RyDeR` one.
Use:
Use:
Time in ms to execute the code that I put on Use of each one.
Source of the benchmark
The results show that ****** method is faster, but ****** method can't return a specific value because it's a macro so you can't return it.
Which are the advantages and disadvantages of each methods? Which is better? Which I should use? Why?
Thanks to all the SA-MP community for always solve my doubts and for being so amazing!
****** method
pawn Код:
#if !defined FALSE
stock bool:FALSE = false;
#endif
#define FormatMessageToAll(%0,%1,%2,%3) do { format(string, %1, (%2), %3); SendClientMessageToAll((%0), string); } while(FALSE)
#define MAX_STRING (3000)
new string[MAX_STRING];
Use:
pawn Код:
FormatMessageToAll(-1, 4, "tes%s", "t");
RyDeR` method
pawn Код:
SendFormatMessage(const iPlayer, const iColor, const szFormat[], { Float, _ }: ...)
{
new iArgs = (numargs() - 3) << 2;
if(iArgs)
{
static s_szBuf[144], s_iAddr1, s_iAddr2;
#emit ADDR.PRI szFormat
#emit STOR.PRI s_iAddr1
for(s_iAddr2 = s_iAddr1 + iArgs, iArgs += 12; s_iAddr2 != s_iAddr1; s_iAddr2 -= 4)
{
#emit LOAD.PRI s_iAddr2
#emit LOAD.I
#emit PUSH.PRI
}
#emit CONST.PRI s_szBuf
#emit PUSH.S szFormat
#emit PUSH.C 144
#emit PUSH.PRI
#emit PUSH.S iArgs
#emit SYSREQ.C format
#emit LCTRL 4
#emit LOAD.S.ALT iArgs
#emit ADD.C 4
#emit ADD
#emit SCTRL 4
return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, s_szBuf) : SendClientMessageToAll(iColor, s_szBuf);
}
return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, szFormat) : SendClientMessageToAll(iColor, szFormat);
}
pawn Код:
SendFormatMessage(-1, -1, "tes%s", "t");
Benchmark
Time in ms to execute the code that I put on Use of each one.
Код:
****** method: 122ms RyDeR` method: 142ms
pawn Код:
#include <a_samp>
#define FILTERSCRIPT
#if !defined FALSE
stock bool:FALSE = false;
#endif
#define FormatMessageToAll(%0,%1,%2,%3) do { format(string, %1, (%2), %3); SendClientMessageToAll((%0), string); } while(FALSE)
#define MAX_STRING (3000)
new string[MAX_STRING];
public OnFilterScriptInit()
{
print("-> OnGameModeInit()");
new tick = GetTickCount();
for(new i = 0; i < 100000; i++)
{
FormatMessageToAll(-1, 4, "tes%s", "t");
}
printf("****** method: %dms", GetTickCount() - tick);
tick = GetTickCount();
for(new i = 0; i < 100000; i++)
{
SendFormatMessage(-1, -1, "tes%s", "t");
}
printf("RyDeR` method: %dms", GetTickCount() - tick);
return 1;
}
SendFormatMessage(const iPlayer, const iColor, const szFormat[], { Float, _ }: ...)
{
new iArgs = (numargs() - 3) << 2;
if(iArgs)
{
static s_szBuf[144], s_iAddr1, s_iAddr2;
#emit ADDR.PRI szFormat
#emit STOR.PRI s_iAddr1
for(s_iAddr2 = s_iAddr1 + iArgs, iArgs += 12; s_iAddr2 != s_iAddr1; s_iAddr2 -= 4)
{
#emit LOAD.PRI s_iAddr2
#emit LOAD.I
#emit PUSH.PRI
}
#emit CONST.PRI s_szBuf
#emit PUSH.S szFormat
#emit PUSH.C 144
#emit PUSH.PRI
#emit PUSH.S iArgs
#emit SYSREQ.C format
#emit LCTRL 4
#emit LOAD.S.ALT iArgs
#emit ADD.C 4
#emit ADD
#emit SCTRL 4
return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, s_szBuf) : SendClientMessageToAll(iColor, s_szBuf);
}
return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, szFormat) : SendClientMessageToAll(iColor, szFormat);
}
The results show that ****** method is faster, but ****** method can't return a specific value because it's a macro so you can't return it.
The doubt
Which are the advantages and disadvantages of each methods? Which is better? Which I should use? Why?
Thanks to all the SA-MP community for always solve my doubts and for being so amazing!