28.03.2010, 16:02
Just a little tutorial on how to speed test your scripts.
Say you want to see how long this while() loop will take.
NOTE: DO NOT put this into your script, this is just an example and will not benefit you. Work out where to put everything on something you want to test yourself. Or you can post here and someone may help you.
You do this with the function GetTickCount();
First, create a variable called tick and give it an array size of 2.
Now above your while() loop put this
This will get how many ticks the server has already returned. 1 tick = 1 ms. You will then after your while function place this
Notice that I've changed the array cell from 0 to 1. This stores the integer into the one variable but in a different slot(cell).
Now to get the time it took in ms we use printf()
We need to minus tick's cell 1 by tick's cell 0 to get the actual time in ms that it took, if we don't, we will get invalid data.
run this in OnGameModeInit() so it shall look like this
Run this, I got this data on 3 different runs
[code=Data]
Run Time
1: 41049
2: 36502
3: 37787
[/code]
This data is non consistant. It's only 3 runs so there is not enough data to gain an average. Run multiple tests to see if you can gain an average time for your server.
Awaran
Say you want to see how long this while() loop will take.
pawn Code:
new a = 0;
while(a < 100000) { printf("Process: %d",a); a++; }
You do this with the function GetTickCount();
First, create a variable called tick and give it an array size of 2.
pawn Code:
new tick[2]
pawn Code:
tick[0] = GetTickCount();
pawn Code:
tick[1] = GetTickCount();
Now to get the time it took in ms we use printf()
pawn Code:
printf("Process time taken: %d",tick[1]-tick[0]);
run this in OnGameModeInit() so it shall look like this
pawn Code:
new a = 0;
new tick[2];
tick[0] = GetTickCount();
while(a < 100000) { printf("Process: %d",a); a++; }
tick[1] = GetTickCount();
printf("Process complete.\nTime taken: %d",tick[1]-tick[0]);
[code=Data]
Run Time
1: 41049
2: 36502
3: 37787
[/code]
This data is non consistant. It's only 3 runs so there is not enough data to gain an average. Run multiple tests to see if you can gain an average time for your server.
Awaran