What of this methods is faster?
#1

What of this methods is more efficient and effective?


DOUBT 1

Which is more efficient between these cases?

Case 1:
pawn Код:
#define TEST "test"
Case 2:
pawn Код:
new TEST[4] = "test";
Case 3:
pawn Код:
new const TEST = "test";
Case 4:
pawn Код:
stock const TEST = "test";

DOUBT 2

Which is more efficient between these cases?

Case 1:
pawn Код:
#define TEST 1
Case 2:
pawn Код:
new TEST = 1;
Case 3:
pawn Код:
new const TEST = 1;
Case 4:
pawn Код:
stock const TEST = 1;

Thanks.
Reply
#2

Strings and Integers? Both are used for different things. Why do you even want to compare whos faster in it?
Reply
#3

^
You're kind of confusing...Why are you comparing them in the first place?
Reply
#4

Err, well they're being used for various purposes. You can test them yourself using 'GetTickCount' function. Just like:

pawn Код:
public OnFilterScriptInit()
{
 new tick = GetTickCount();
 static test = 5;
 printf("Time taken while executing filterscript with static test %d : %d", test, GetTickCount() - tick);
 return 1;
}
Reply
#5

I have edited the thread, now you understand me?
Reply
#6

Use the "GetTickCount" function, very simplistic.
Reply
#7

I don't mean faster, I mean efficient and effective, please someone who know could tell me please?
Reply
#8

if you use some variables which you don't want to remember it always then use define.
usually I use define for dialogs ids, like
pawn Код:
#define DIALOG_HELP 12
this way better, if you want to declar CONST numbers like п = 3.14... then better use const.
if you have a lot messages or other text then use
pawn Код:
new AlotText[][2] =
{
{"Text first"},{"Text second"}
};
you can use that like this
pawn Код:
format(string,256,"( ! ) first TXT:%s second: %s",AlotText[0],AlotText[1]);
Reply
#9

I know that having many macros affects the compile time. I also know that literals are faster than variables. But I honestly doubt it would have any effect at runtime if you chose to use constant variables.

In any case, using const instead of new is better if you know that the value of the variable is never to change. There are also instances where macros cannot be used. For example declaring a large array of floats.

As for keeping track of dialog ids, I use an enumerator. Guaranteed to never have a duplicate id.
Reply
#10

Oh, Thanks ******. Where I can find a lot of code improvements?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)