IS4Code / PawnPlus

A SA-MP plugin enhancing the capabilities of the Pawn programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Performance issue? SendClientMessageToAllStr vs SendClientMessageToAll

Yousha opened this issue · comments

Why is using SendClientMessageToAllStr() is a bit slower than using SendClientMessageToAll() ?
The difference is about ~60ms

SendClientMessageToAll

   new string[48];
   format(string, 48, "Test. Test. Test. Test. Test. Test. Test. Test.");
   new startTick, stopTick;
   startTick = GetTickCount();
   for (new i; i < 1000000; i ++)
   {
      SendClientMessageToAll(-1, string);
   }
   stopTick = GetTickCount();
   printf("------ %i ms -------", stopTick - startTick);

Result: 802 ms

SendClientMessageToAllStr

   new String:string = str_new("Test. Test. Test. Test. Test. Test. Test. Test.");
   new startTick, stopTick;
   startTick = GetTickCount();
   for (new i; i < 1000000; i ++)
   {
      SendClientMessageToAllStr(-1, string);
   }
   stopTick = GetTickCount();
   printf("------ %i ms -------", stopTick - startTick);

Result: 857 ms

Platform

Hardware: Intel x64
OS: Windows 7 32bit
PAWN: 3.10.8
Compile arguments: -d0 -O1 -v3
SAMP: 0.3.7 R

commented

One way to decrease the slight overhead is by caching the AmxString value which is passed to the function. After that, I get only 1 % overhead, which is understandable, since the new function does more than the original (compute the absolute address, find it in the string pool). The relative difference in the performance is really negligible.