[HOW-TO] Speed Test Your Script
#1

Just a little tutorial on how to speed test your scripts.

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++; }
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.

pawn Code:
new tick[2]
Now above your while() loop put this

pawn Code:
tick[0] = GetTickCount();
This will get how many ticks the server has already returned. 1 tick = 1 ms. You will then after your while function place this

pawn Code:
tick[1] = GetTickCount();
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()

pawn Code:
printf("Process time taken: %d",tick[1]-tick[0]);
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

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]);
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
Reply
#2

Wow nice, I will use it! Thanks!
Reply
#3

Ehhh ? All your doing is timing a while loop, how does that tell you anything about your script ?
Reply
#4

Quote:
Originally Posted by Zimon95
Wow nice, I will use it! Thanks!
I lol'd.
Reply
#5

Quote:
Originally Posted by Kyosaur!!
Ehhh ? All your doing is timing a while loop, how does that tell you anything about your script ?
That would be the example script. I just needed something short that would take a while to process fully. And the while loop did. So i used it as an example.

If you use the while loop in your server its kinda stupid. Usually people have more brains than that.
Reply
#6

ROFL nice i done this:
1. 7474
2. 7624
3. 7613
4. 7515
5. 7403
6. 7608
7. 7606
8. 7763
9. 7685

Average of 7573
Reply
#7

You got an average of 7.5 seconds? How many loops did you run (the number in red)

while(a < 100000) { printf("Process: %d",a); a++; }
Reply
#8

Quote:
Originally Posted by {Awaran};
You got an average of 7.5 seconds? How many loops did you run (the number in red)

while(a < 100000) { printf("Process: %d",a); a++; }
100000

Just copyed the lines from the first post
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)