17.09.2011, 14:36
So, what do you think would be better in performance?
checking:
or strcmp, the last text with the current one?
I know hashing would save a lot of memory, but i'm thinking of speed now.
If anyone could give me a benchmarking script for this issue, I would test it myself.
Edit:
I'm kicking only if the text repeats ~30 times, so the collisions don't really matter. Maybe this would do:
checking:
pawn Код:
if(udb_hash(text) == lasttext[playerid])
stock udb_hash(buf[])
{
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
I know hashing would save a lot of memory, but i'm thinking of speed now.
If anyone could give me a benchmarking script for this issue, I would test it myself.
Edit:
I'm kicking only if the text repeats ~30 times, so the collisions don't really matter. Maybe this would do:
pawn Код:
stock small_hash(buf[])
{
new int,len=strlen(buf);
for(new i=0;i<len;i++) int+=buf[i];
return int;
}