Anti-Spam(strcmp vs udb_Hash)
#1

So, what do you think would be better in performance?
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;
}
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:
pawn Код:
stock small_hash(buf[])
{
    new int,len=strlen(buf);
    for(new i=0;i<len;i++) int+=buf[i];
    return int;
}
Reply
#2

First of all, hashing is not about speed, it's about protecting your users.

For an anti-spam, you would use strcmp to stop people from writing the same thing again. This is not the purpose of hashing.

If you want to benchmark it, then just use GetTickCount above the function and below the function, then subtract the times and you have how long it took for that section of code to complete execution, for example:

pawn Код:
new time;

time = GetTickCount();

// Execute a piece of code

printf("This took %dms to complete", GetTickCount() - time);
Reply
#3

Quote:

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;
}
I tought about the same a few weeks ago, and the checks showed that strcmp is extremely powerful against this hash. (tested with 4,000,000 cells though :Đ)

Edit: if you'd use this hash, speedup:
pawn Код:
stock small_hash(buf[])
{
    new i = -1, int = 0;
    while (buf[++i] != 0) int += buf[i];
    return int;
}
as strlen loops through the whole string, which is already done by us.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)