Advertisement
Guest User

Slice

a guest
Nov 8th, 2010
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.53 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #pragma tabsize 0
  4.  
  5. #define START_BENCH(%0); \
  6. { \
  7.     new iMilliSeconds = %0, iCount = 0, iStartTick, iTick; \
  8.     do { } while ( iStartTick == GetTickCount( ) ); \
  9.     iTick = GetTickCount( ); \
  10.     iStartTick = iTick; \
  11.     while ( iTick - iStartTick < iMilliSeconds ) \
  12.     { \
  13.         ++iCount;
  14.  
  15. #define FINISH_BENCH(%0); \
  16.         iTick = GetTickCount( ); \
  17.     } \
  18.     printf( " Bench for " %0 ": executes, by average, %d times/ms.", iCount / iMilliSeconds ); \
  19. }
  20.  
  21. stock strcpy_1(dest[], source[], len = -1)
  22. {
  23.     new
  24.         i;
  25.     if (len == -1) len = strlen(source);
  26.     while (i < len) dest[i] = source[i++];
  27.     dest[i] = 0;
  28. }
  29.  
  30. stock strcpy_2(dest[], source[])
  31. {
  32.     new i = -1;
  33.    
  34.     do
  35.         dest[++i] = source[i];
  36.     while ( dest[ i ] );
  37. }
  38.  
  39. public OnFilterScriptInit( )
  40. {
  41.     new szSource[ ] = \"cadnifgjghaj6he890fJT#)=ASJ\\sdfaf£\sf\v\\asfai2r2j90J)=J#)=Jf09ASFASPfasiof(ShcvnoAfsaj2389ajfa";
  42.    
  43.     new szDest[ 1234 ];
  44.    
  45.     printf( "String copying benchmark" );
  46.  
  47.     START_BENCH( 1000 );
  48.    
  49.         memcpy( szDest, szSource, _, ( strlen( szSource ) + 1 ) * 4 );
  50.    
  51.     FINISH_BENCH( "memcpy" );
  52.  
  53.     START_BENCH( 1000 );
  54.    
  55.         format( szDest, sizeof( szDest ), "%s", szSource );
  56.    
  57.     FINISH_BENCH( "format" );
  58.    
  59.     START_BENCH( 1000 );
  60.    
  61.         strcpy_1( szDest, szSource );
  62.    
  63.     FINISH_BENCH( "strcpy 1" );
  64.    
  65.     START_BENCH( 1000 );
  66.    
  67.         strcpy_2( szDest, szSource );
  68.    
  69.     FINISH_BENCH( "strcpy 2" );
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement