Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.90 KB | None | 0 0
  1. #include                        a_samp
  2.  
  3. #define system::                            system_
  4.  
  5. // Slice's benchmarking macros.
  6. #define START_BENCH(%0); {new __a=%0,__b=0,__c,__d=GetTickCount(),__e=1;do{}\
  7.     while(__d==GetTickCount());__c=GetTickCount();__d=__c;while(__c-__d<__a||\
  8.     __e){if(__e){if(__c-__d>=__a){__e=0;__c=GetTickCount();do{}while(__c==\
  9.     GetTickCount());__c=GetTickCount();__d=__c;__b=0;}}{
  10.    
  11. #define FINISH_BENCH(%0); }__b++;__c=GetTickCount();}printf(" Bench for "\
  12.     %0": executes, by average, %.2f times/ms.",floatdiv(__b,__a));}
  13.  
  14. public
  15.     OnFilterScriptInit()
  16. {
  17.     // Strings match each other.
  18.     START_BENCH( 10000 );
  19.     {
  20.         strcmp("@The quick brown fox jumps over the lazy dog.", "@The quick brown fox jumps over the lazy dog.");
  21.     }
  22.     FINISH_BENCH( "strcmp" );
  23.     START_BENCH( 10000 );
  24.     {
  25.         system::strCheck("@The quick brown fox jumps over the lazy dog.", "@The quick brown fox jumps over the lazy dog.");
  26.     }
  27.     FINISH_BENCH( "system::strCheck" );
  28.  
  29.     // Strings don't match each other.
  30.     START_BENCH( 10000 );
  31.     {
  32.         strcmp("@The quick brown fox jumps over the lazy dog. ", "@The quick brown fox jumps over the lazy dog..");
  33.     }
  34.     FINISH_BENCH( "strcmp" );
  35.     START_BENCH( 10000 );
  36.     {
  37.         system::strCheck("@The quick brown fox jumps over the lazy dog. ", "@The quick brown fox jumps over the lazy dog..");
  38.     }
  39.     FINISH_BENCH( "system::strCheck" );
  40.     return true;
  41. }
  42.  
  43. /*
  44.     system::strCheck:
  45.         Check if the strings ('s_' and '_s') match each other.
  46.  
  47.     Arguments:
  48.         s_[]    First string.
  49.         _s[]    Second string.
  50.  
  51.     Returns:
  52.         ? False, True.
  53.  
  54.     Notes:
  55.         Similar to strcmp, but faster.
  56. */
  57. stock
  58.     system::strCheck(s_[], _s[])
  59. {
  60.     new
  61.             c = 0
  62.           , bool:b = true
  63.     ;
  64.     while (max(strlen(s_), strlen(_s)) != c)
  65.     {
  66.         if (s_[c] != _s[c])
  67.         {
  68.             b
  69.                 = false
  70.             ;
  71.         }
  72.         ++
  73.             c
  74.         ;
  75.     }
  76.     if (b)
  77.     {
  78.         return true;
  79.     }
  80.     else
  81.     {
  82.             return false;
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement