[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


Messages In This Thread
[HOW-TO] Speed Test Your Script - by pagie1111 - 28.03.2010, 16:02
Re: [HOW-TO] Speed Test Your Script - by Zimon95 - 28.03.2010, 16:05
Re: [HOW-TO] Speed Test Your Script - by Kyosaur - 28.03.2010, 16:35
Re: [HOW-TO] Speed Test Your Script - by Finn - 28.03.2010, 16:38
Re: [HOW-TO] Speed Test Your Script - by pagie1111 - 28.03.2010, 16:47
Re: [HOW-TO] Speed Test Your Script - by shotyoudie - 28.03.2010, 16:55
Re: [HOW-TO] Speed Test Your Script - by pagie1111 - 28.03.2010, 17:08
Re: [HOW-TO] Speed Test Your Script - by shotyoudie - 29.03.2010, 13:06

Forum Jump:


Users browsing this thread: 1 Guest(s)