12.07.2017, 22:29
This is even slower then using strcmp...
Code used:
(Sorry if I missunderstod this include.)
Код:
Comparing a string 1000 times in a row using switch(). Loop finished after: 6 milliseconds. .. Comparing a string 1000 times in a row using strcmp. Loop finished after: 2 milliseconds.
Код:
Comparing a string 100,000 times in a row using switch(). Loop finished after: 330 milliseconds. .. Comparing a string 100,000 times in a row using strcmp. Loop finished after: 134 milliseconds.
Код:
Comparing a string 500,000 times in a row using switch(). Loop finished after: 1636 milliseconds. .. Comparing a string 500,000 times in a row using strcmp. Loop finished after: 664 milliseconds.
PHP код:
#include <a_samp>
#include <YSI\y_stringhash>
main() {
printf("Comparing a string 1000 times in a row using switch().");
new count = GetTickCount();
for(new i = 0; i < 1001; i++) {
new string[144];
format(string, 144, "something random (%i)", random(10000));
switch(YHash(string)) {
case _H<dfsd>: {
print("waow");
}
case _H<fghfggfhgf>: {
print("waow");
}
case _H<fghfsdfsdfggfhgf>: {
print("waow");
}
}
}
printf("Loop finished after: %i milliseconds.", GetTickCount()-count);
print("..");
printf("Comparing a string 1000 times in a row using strcmp.");
count = GetTickCount();
for(new i = 0; i < 1001; i++) {
new string[144];
format(string, 144, "something random (%i)", random(10000));
if(!strcmp(string, "dfsd")) {
print("waow");
}
else if(!strcmp(string, "fghfggfhgf")) {
print("waow");
}
else if(!strcmp(string, "fghfsdfsdfggfhgf")) {
print("waow");
}
}
printf("Loop finished after: %i milliseconds.", GetTickCount()-count);
}