This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <a_samp> | |
/* | |
Consts | |
*/ | |
#define TESTING_STRING " oc, ococ,ococ,ococ,oc oc,ococ,ococ,ococ,ococ,ococ,oco" | |
#define RESULT_STRING "oc,ococ,ococ,ococ,ococ,ococ,ococ,ococ,ococ,ococ,oco" | |
const PROFILE_ITERATIONS_MAJOR = 1000; | |
const PROFILE_ITERATIONS_MINOR = 100; | |
/* | |
User info | |
*/ | |
enum uInfo { | |
name[128], | |
time, | |
bool:isright, | |
} | |
new users[][uInfo] = { | |
{"Tracer"}, | |
{"Dalglish"}, | |
{"g3o0or"}, | |
{"MellikJKE"}, | |
{"iBorland"}, | |
{"ziggi"} | |
}; | |
/* | |
Macroses | |
*/ | |
#define RIGHT_TEST(%0,%1);\ | |
{\ | |
new str[] = #TESTING_STRING;\ | |
RemoveSpaces_%0(str);\ | |
users[%1][isright] = strcmp(str, RESULT_STRING) == 0;\ | |
\ | |
new name_spaces[128];\ | |
new max_name_length = GetMaxNameLength();\ | |
MakeSymbols(name_spaces, ' ', max_name_length - strlen(users[%1][name]) + 1);\ | |
\ | |
printf("%s:%s\"%s\"", #%0, name_spaces, str);\ | |
} | |
#define SPEED_TEST(%0);\ | |
for (new j = 0; j < PROFILE_ITERATIONS_MINOR; j++) {\ | |
new str[] = #TESTING_STRING;\ | |
RemoveSpaces_%0(str);\ | |
} | |
#define SPEED_START(%0)\ | |
%0 = GetTickCount() | |
#define SPEED_END(%0,%1)\ | |
%1 += GetTickCount() - %0 | |
/* | |
Main | |
*/ | |
main() | |
{ | |
print("\n"); | |
RIGHT_TEST(Tracer, 0); | |
RIGHT_TEST(Dalglish, 1); | |
RIGHT_TEST(g3o0or, 2); | |
RIGHT_TEST(MellikJKE, 3); | |
RIGHT_TEST(iBorland, 4); | |
RIGHT_TEST(ziggi, 5); | |
print("\n"); | |
new bufer; | |
for (new i = 0; i < PROFILE_ITERATIONS_MAJOR; i++) { | |
SPEED_START(bufer); | |
SPEED_TEST(Tracer); | |
SPEED_END(bufer,users[0][time]); | |
SPEED_START(bufer); | |
SPEED_TEST(Dalglish); | |
SPEED_END(bufer,users[1][time]); | |
SPEED_START(bufer); | |
SPEED_TEST(g3o0or); | |
SPEED_END(bufer,users[2][time]); | |
SPEED_START(bufer); | |
SPEED_TEST(MellikJKE); | |
SPEED_END(bufer,users[3][time]); | |
SPEED_START(bufer); | |
SPEED_TEST(iBorland); | |
SPEED_END(bufer,users[4][time]); | |
SPEED_START(bufer); | |
SPEED_TEST(ziggi); | |
SPEED_END(bufer,users[5][time]); | |
} | |
new name_spaces[128]; | |
new max_name_length = GetMaxNameLength(); | |
MakeSymbols(name_spaces, ' ', max_name_length - 4 + 1); | |
printf(" Name%s| Status | Time", name_spaces); | |
MakeSymbols(name_spaces, '-', max_name_length - 4 + 1 + 20); | |
print(name_spaces); | |
for (new i = 0; i < sizeof(users); i++) { | |
MakeSymbols(name_spaces, ' ', max_name_length - strlen(users[i][name]) + 1); | |
printf(" %s%s| %s | %d", users[i][name], name_spaces, users[i][isright] ? "RIGHT" : "WRONG", users[i][time]); | |
} | |
print("\n"); | |
} | |
/* | |
Make good look | |
*/ | |
stock MakeSymbols(string[], const symbol, const length, const max_length = sizeof(string)) | |
{ | |
if (length >= max_length || length < 0) { | |
string[0] = '\0'; | |
return string; | |
} | |
for (new i = 0; i < length; i++) { | |
string[i] = symbol; | |
} | |
string[length] = '\0'; | |
return string; | |
} | |
stock GetMaxNameLength() | |
{ | |
new | |
current_value, | |
max_value = 0; | |
for (new i = 0; i < sizeof(users); i++) { | |
current_value = strlen(users[i][name]); | |
if (current_value > max_value) { | |
max_value = current_value; | |
} | |
} | |
return max_value; | |
} | |
/* | |
Functions | |
*/ | |
stock RemoveSpaces_Tracer(string[]) | |
{ | |
for(new i, l = strlen(string); i < l; ++i) | |
{ | |
if(string[i] != 32)continue;//32 - ID ionoiai neiaiea | |
strdel(string, i, i+1); | |
i--; | |
} | |
} | |
stock RemoveSpaces_Dalglish(input[], DelSymbol = ' ') | |
{ | |
new pos; | |
for(pos = strlen(input); input[pos] <= DelSymbol; ) pos--; | |
input[pos + 1] = EOS; | |
for(pos = 0; input[pos] <= DelSymbol; ) pos++; | |
strdel(input, 0, pos); | |
} | |
stock RemoveSpaces_g3o0or(string[]) | |
{ | |
new write_pos; | |
for(new read_pos; string[read_pos] != '\0'; read_pos++) | |
{ | |
if(string[read_pos] == ' ') | |
{ | |
continue; | |
} | |
else | |
{ | |
string[write_pos++] = string[read_pos]; | |
} | |
} | |
string[write_pos] = '\0'; | |
} | |
stock RemoveSpaces_MellikJKE(String[]) | |
{ | |
new s = ' '; | |
for(new i = 0; i!= strlen(String); i++) | |
{ | |
if(String[i] == s) | |
strdel(String, i, i+1); | |
} | |
return String; | |
} | |
stock RemoveSpaces_iBorland(string[]) | |
{ | |
for(new i = 0; strfind(string," ") != -1; i++) | |
{ | |
strdel(string, strfind(string," "), strfind(string," ") + 1); | |
} | |
} | |
stock RemoveSpaces_Untonyst(string[]) | |
{ | |
for(new i; string[i] != '\0'; i++) | |
if(string[i] == ' ') | |
strdel(string, i, i + 1), --i; | |
} | |
stock RemoveSpaces_ziggi(string[]) | |
{ | |
for (new i = 0, start = -1; string[i] != '\0'; i++) { | |
if (string[i] == ' ') { | |
if (start == -1) { | |
start = i; | |
} | |
} else { | |
if (start != -1) { | |
strdel(string, start, i); | |
i -= start + 2; | |
start = -1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment