Which method is better? (****** vs. RyDeR`)
#1

I want to know which method is better to send a formatted message, ****** method or RyDeR` one.

****** 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);
}
Use:
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
Source of the benchmark
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!
Reply
#2

Oh thanks ****** for the fast answer. However, where are the Slice method?


Thank you!
Reply
#3

@******, well I've seen that posted by RyDeR on Useful functions topic.
OT:Why don't you try checking out 'y_va' ?
Reply
#4

This is help section not fight section i thing so? Don't make 2 people to fight..!!!
Reply
#5

Quote:
Originally Posted by aslan890
Посмотреть сообщение
This is help section not fight section i thing so? Don't make 2 people to fight..!!!
You have no idea what you're saying.
Reply
#6

Quote:
Originally Posted by Mr.Anonymous
Посмотреть сообщение
You have no idea what you're saying.
Just look at his name.
Reply
#7

Quote:
Originally Posted by Mr.Anonymous
Посмотреть сообщение
You have no idea what you're saying.
+1.

The idea isn't create a fight, there no a competition. This is for making SA-MP better, for creating better gamemodes for the users and for the developers learn new and better techniques.


@******: Why you do that code:

pawn Код:
#if !defined FALSE    
stock bool:FALSE = false;
#endif
And why do you do the do { code } while(FALSE) ? FALSE not always going to be false?

Thanks for answering and sorry if I ask a lot, I want to learn and help
Reply
#8

Oh, now I understand. Thanks ****** and happy new year!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)