08.01.2014, 01:52
(
Последний раз редактировалось Swedky; 08.01.2014 в 06:19.
)
Well, in this tutorial I will teach them to how doing speed tests in our codes.
The first thing that we must know is what we are going to use:
Probably wonder: And how is it possible to do speed tests in the codes? The response is simple: SA-MP runs in an alone thread, with this I refer that the actions execute 1 for 1. Or, an action is executed by a certain moment, on having finished this moment the following one is executed and so on.
Let's see the following example:
Do this test of speed and compare the results with this one:
They will notice that the result is very much minor that the previous one.
These are my results:
Do they see the notable thing that is the difference?
Now already we know how to do the speed tests.
Here another example: using a normal loop and foreach:
My results:
Note: I used '500' slot's to differentiate well the results.
I hope that it has served them.
If have some doubt, or I have been wrong in something make it know.
Regards.
The first thing that we must know is what we are going to use:
- A variable:
- With her we will store values with....
- GetTickCount:
- In him the variables will be stored. (GetTickCount returns values in milliseconds).
Probably wonder: And how is it possible to do speed tests in the codes? The response is simple: SA-MP runs in an alone thread, with this I refer that the actions execute 1 for 1. Or, an action is executed by a certain moment, on having finished this moment the following one is executed and so on.
Let's see the following example:
pawn Код:
public OnFilterScriptInit()
{
new count = GetTickCount();
for(new i = 0; i < 50; i++)
{
SendRconCommand("gmx");
}
printf("Time in executing: %i.", GetTickCount()-count);
return 1;
}
Do this test of speed and compare the results with this one:
pawn Код:
public OnFilterScriptInit()
{
new count = GetTickCount();
for(new i = 0; i < 10; i++)
{
SendRconCommand("gmx");
}
printf("Time in executing: %i.", GetTickCount()-count);
return 1;
}
They will notice that the result is very much minor that the previous one.
These are my results:
pawn Код:
// Loop of 50 repetitions:
[23:03:50] Time in executing: 73.
[23:03:55] Time in executing: 86.
[23:04:02] Time in executing: 80.
// Rounding: 79
// Loop of 10 repetitions:
[23:09:16] Time in executing: 18.
[23:09:21] Time in executing: 22.
[23:09:29] Time in executing: 17.
// Rounding: 19.
Now already we know how to do the speed tests.
Here another example: using a normal loop and foreach:
pawn Код:
// Using a normal loop:
CMD:test(playerid, params[])
{
new count = GetTickCount();
new string[60];
new Nick[MAX_PLAYER_NAME];
GetPlayerName(playerid, Nick, sizeof(Nick));
format(string, sizeof(string), "* Your principal information: %s[%d].", Nick, playerid);
for(new i = 0; i < GetMaxPlayers(); i++)
{
if(IsPlayerAdmin(i))
{
SendClientMessage(i, -1, string);
}
}
printf("Time in executing: %i.", GetTickCount()-count);
return 1;
}
// Using foreach:
CMD:test2(playerid, params[])
{
new count = GetTickCount();
new string[60];
new Nick[MAX_PLAYER_NAME];
GetPlayerName(playerid, Nick, sizeof(Nick));
format(string, sizeof(string), "* Your principal information: %s[%d].", Nick, playerid);
foreach(new i: Player)
{
if(IsPlayerAdmin(i))
{
SendClientMessage(i, -1, string);
}
}
printf("Time in executing: %i.", GetTickCount()-count);
return 1;
}
My results:
pawn Код:
[23:52:04] Time in executing (normal loop): 75.
[23:52:16] Time in executing (normal loop): 83.
[23:52:17] Time in executing (normal loop): 87.
[23:52:18] Time in executing (foreach): 22.
[23:52:19] Time in executing (foreach): 26.
[23:52:20] Time in executing (foreach): 17.
I hope that it has served them.
If have some doubt, or I have been wrong in something make it know.
Regards.