12.01.2014, 12:13
Hello all.
I compiled fs at different debug level and made speed test.
There are 2 functions (prototypes):
stock Games_trim2(str[], Char = ' ');
stock Games_trimE(str[], Char = ' ');
Each function does the same thing - cuts the sign from the start and end of the line.
As and a standard function trim() in many programming languages.
-------------
At every debug level - different function wins in speed.
Results:
When debug level 0 wins function Games_trim2, and when debug level 3 - Games_trimE.
Why is this happening?
And what kind debug level you recommend?
I compiled fs at different debug level and made speed test.
There are 2 functions (prototypes):
stock Games_trim2(str[], Char = ' ');
stock Games_trimE(str[], Char = ' ');
Each function does the same thing - cuts the sign from the start and end of the line.
As and a standard function trim() in many programming languages.
-------------
At every debug level - different function wins in speed.
Results:
PHP код:
//d0
[15:24:05] - Games_trim2(): 4995 (ms)
[15:24:11] - Games_trimE(): 5364 (ms)
[15:24:11] - Games_trim2(): 787 (ms)
[15:24:12] - Games_trimE(): 903 (ms)
//d3
[15:27:53] - Games_trim2(): 9057 (ms)
[15:27:58] - Games_trimE(): 5086 (ms)
[15:27:59] - Games_trim2(): 1048 (ms)
[15:28:00] - Games_trimE(): 865 (ms)
PHP код:
#include <a_samp>
public OnFilterScriptInit()
{
new time = GetTickCount();
for(new i; i < 1000000; i++) {
new str[] ="+++++++++++++++++++++++++++++++++++++++string++++++++++++++++++++++++++++++++++++++++++";
Games_trim2(str, '+');
}
printf("- Games_trim2(): %i (ms)", GetTickCount()-time);
time = GetTickCount();
for(new i; i < 1000000; i++) {
new str[] = "+++++++++++++++++++++++++++++++++++++++string++++++++++++++++++++++++++++++++++++++++++";
Games_trimE(str, '+');
}
printf("- Games_trimE(): %i (ms)\n\n", GetTickCount()-time);
time = GetTickCount();
for(new i; i < 1000000; i++) {
new str[] = "+string+";
Games_trim2(str, '+');
}
printf("- Games_trim2(): %i (ms)", GetTickCount()-time);
time = GetTickCount();
for(new i; i < 1000000; i++) {
new str[] = "+string+";
Games_trimE(str, '+');
}
printf("- Games_trimE(): %i (ms)\n\n", GetTickCount()-time);
}
stock Games_trim2(str[], Char = ' ')
{
new i;
while(str[i] == Char) i++;
strdel(str, 0, i);
if(!i) return 1;
i = strlen(str) - 1;
while(str[i] == Char) i--;
str[i + 1] = '\0';
return 1;
}
Games_trimE(str[], Char = ' '){
new i = -1;
while(str[++i] == Char){}
strdel(str, 0, i);
if(!i) return ;
i = strlen(str);
while(str[--i] == Char){}
str[++i] = '\0';
return ;
}
Why is this happening?
And what kind debug level you recommend?