Getting the time a function takes to do something?
#1

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 
istring[i]; i++)
    {
        
count++;
    }
    return 
count;

Don't tell me that strlen already does it.
Reply
#2

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;
}
Reply
#3

https://sampforum.blast.hk/showthread.php?tid=218491
Reply
#4

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.
Reply
#5

Код:
[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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)