Advertisement
Guest User

Untitled

a guest
Jun 1st, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.80 KB | None | 0 0
  1. public OnRconCommand(cmd[])
  2. {
  3.     if (!strcmp(cmd, "test", true)) {
  4.         const
  5.             num_iters = 1000000;
  6.         new
  7.             szBuffer[512],
  8.             tick_count;
  9.  
  10.         tick_count = GetTickCount();
  11.         for (new iter; iter < num_iters; iter++) {
  12.             szBuffer = "#0 #0 #0";
  13.  
  14.             for (new pos = -1, num_names; (pos = strfind(szBuffer, "#", false, pos + 1)) != -1 && num_names < 4;) {
  15.                 new
  16.                     str[45],
  17.                     num_digits,
  18.                     _id = INVALID_PLAYER_ID
  19.                 ;
  20.  
  21.                 for (new i = pos + 1; i < sizeof(szBuffer) && '0' <= szBuffer[i] <= '9' && num_digits < 3; i++) {
  22.                     str[num_digits++] = szBuffer[i];
  23.                     _id = strval(str);
  24.                 }
  25.  
  26.                 if (_id != INVALID_PLAYER_ID && IsPlayerConnected(_id)) {
  27.                     format(str, sizeof(str), "{%06x}%s{ffffff}", GetPlayerColor(_id) >>> 8, playerName[_id]);
  28.                     strdel(szBuffer, pos, pos + num_digits + 1);
  29.                     strins(szBuffer, str, pos);
  30.                     num_names++;
  31.                 }
  32.             }
  33.         }
  34.         printf("for | time: %d ticks", GetTickCount()-tick_count);
  35.  
  36.         tick_count = GetTickCount();
  37.         for (new iter; iter < num_iters; iter++) {
  38.             szBuffer = "#0 #0 #0";
  39.  
  40.             new
  41.                 pos = -1,
  42.                 str[50],
  43.                 num_names,
  44.                 num_digits,
  45.                 _id
  46.             ;
  47.  
  48.             while ((pos = strfind(szBuffer, "#", false, pos + 1)) != -1 && num_names < 4) {
  49.                 num_digits = 0;
  50.                 _id = INVALID_PLAYER_ID;
  51.  
  52.                 for (new i = pos + 1; i < sizeof(szBuffer) && '0' <= szBuffer[i] <= '9' && num_digits < 3; i++) {
  53.                     str[num_digits++] = szBuffer[i];
  54.                     _id = strval(str);
  55.                 }
  56.  
  57.                 if (_id != INVALID_PLAYER_ID && IsPlayerConnected(_id)) {
  58.                     format(str, sizeof(str), "{%06x}%s{ffffff}", GetPlayerColor(_id) >>> 8, playerName[_id]);
  59.                     strdel(szBuffer, pos, pos + num_digits + 1);
  60.                     strins(szBuffer, str, pos);
  61.                     num_names++;
  62.                 }
  63.             }
  64.         }
  65.         printf("while | time: %d ticks", GetTickCount()-tick_count);
  66.         return 1;
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement