Getting the time a function takes to do something? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting the time a function takes to do something? (
/showthread.php?tid=464791)
Getting the time a function takes to do something? -
Magic_Time - 19.09.2013
Hi, I'm new at this.
How can I check the time that function takes to get a string lenght?
PHP код:
stock GetLength(string[])
{
new count;
for(new i; string[i]; i++)
{
count++;
}
return count;
}
Don't tell me that strlen already does it.
Re: Getting the time a function takes to do something? -
Lordzy - 19.09.2013
Use
GetTickCount function to know the time.
pawn Код:
public OnFilterScriptInit()
{
new tick = GetTickCount();
printf("Time taken to determine the length of 'Hi there' : %d (Len : %d)", GetTickCount() - tick, GetLength("Hi there"));
return 1;
}
stock GetLength(string[])
{
new count;
for(new i; string[i]; i++)
{
count++;
}
return count;
}
Re: Getting the time a function takes to do something? -
zSuYaNw - 19.09.2013
https://sampforum.blast.hk/showthread.php?tid=218491
Re: Getting the time a function takes to do something? -
Magic_Time - 19.09.2013
Which one is faster, either strlen or the GetLength one?
I tried the benchmarking function by Slice, I have the following results:
Код:
[23:27:43] Bench for GetLength: executes, by average, 438.30 times/ms.
[23:27:45] Bench for strlen: executes, by average, 592.69 times/ms.
Re: Getting the time a function takes to do something? -
zSuYaNw - 19.09.2013
Код:
[01:39:30] Bench for GetLenght: executes, by average, 949.48 times/ms.
[01:39:30] Bench for strlen: executes, by average, 2914.92 times/ms.
your code.