Advertisement
Chaoz

a_bucles.inc speedtest

Jun 16th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.65 KB | None | 0 0
  1. #include <a_samp>
  2. #include <foreach>
  3. #include <a_inc>
  4. include>a_bucles;
  5. #include <a_inc2>
  6.  
  7. enum TIME_ENUM
  8. {
  9.     Alloc,
  10.     For,
  11.     Delete,
  12.     Find,
  13.     Rand
  14. };
  15.  
  16. #define USE_FILE
  17.  
  18. #define MAX_VALUE   (500)
  19. #define MAX_VALUE2 (15)
  20.  
  21. new
  22.     Iterator:YSI_Iter<MAX_VALUE>;
  23.  
  24. public OnFilterScriptInit()
  25. {
  26.     new
  27.         i,
  28.         tmp,
  29.         time[2][TIME_ENUM][MAX_VALUE2],
  30.         Totals[2][TIME_ENUM],
  31.         #if defined USE_FILE
  32.             File:fHnd,
  33.             str[32],
  34.         #endif
  35.         Bucle:AB_Iter<MAX_VALUE>;
  36.  
  37.     #if defined USE_FILE
  38.         fHnd = fopen("a_bucles speedtest.txt", io_write);
  39.         format(str, 32, "Items: %d(%d)\r\n", MAX_VALUE, MAX_VALUE2);
  40.         fwrite(fHnd, str);
  41.     #else
  42.         printf("Items: %d(%d)", MAX_VALUE, MAX_VALUE2);
  43.     #endif
  44.  
  45.     for(new k; k<MAX_VALUE2; k++)
  46.     {
  47.         Iter_Clear(YSI_Iter);
  48.         forLi(AB_Iter);
  49.         time[0][Alloc][k] = GetTickCount();
  50.         for(i=0; i<MAX_VALUE; i++)
  51.             Iter_Add(YSI_Iter, i);
  52.         time[0][Alloc][k] = GetTickCount() - time[0][Alloc][k];
  53.         Totals[0][Alloc] += time[0][Alloc][k];
  54.  
  55.         time[1][Alloc][k] = GetTickCount();
  56.         for(i=0; i<MAX_VALUE; i++)
  57.             forAg(AB_Iter, i);
  58.         time[1][Alloc][k] = GetTickCount() - time[1][Alloc][k];
  59.         Totals[1][Alloc] += time[1][Alloc][k];
  60.         //--------------------------------------------------
  61.        
  62.         time[0][For][k] = GetTickCount();
  63.         tmp = 0;
  64.         foreach(i:YSI_Iter)
  65.             tmp += i;
  66.         time[0][For][k] = GetTickCount() - time[0][For][k];
  67.         Totals[0][For] += time[0][For][k];
  68.  
  69.         time[1][For][k] = GetTickCount();
  70.         tmp = 0;
  71.         forEach(j,AB_Iter)
  72.             tmp += j;
  73.         time[1][For][k] = GetTickCount() - time[1][For][k];
  74.         Totals[1][For] += time[1][For][k];
  75.         //--------------------------------------------------
  76.        
  77.         time[0][Delete][k] = GetTickCount();
  78.         for(i=0; i<MAX_VALUE; i++)
  79.             Iter_Remove(YSI_Iter, i);
  80.         time[0][Delete][k] = GetTickCount() - time[0][Delete][k];
  81.         Totals[0][Delete] += time[0][Delete][k];
  82.  
  83.         time[1][Delete][k] = GetTickCount();
  84.         for(i=0; i<MAX_VALUE; i++)
  85.             forEl(AB_Iter, i);
  86.         time[1][Delete][k] = GetTickCount() - time[1][Delete][k];
  87.         Totals[1][Delete] += time[1][Delete][k];
  88.         //--------------------------------------------------
  89.        
  90.         for(i=0; i<MAX_VALUE; i+=2)
  91.             Iter_Add(YSI_Iter, i);
  92.  
  93.         for(i=0; i<MAX_VALUE; i+=2)
  94.             forAg(AB_Iter, i);
  95.  
  96.         time[0][Find][k] = GetTickCount();
  97.         for(i=0; i<MAX_VALUE; i++)
  98.             Iter_Contains(YSI_Iter, i);
  99.         time[0][Find][k] = GetTickCount() - time[0][Find][k];
  100.         Totals[0][Find] += time[0][Find][k];
  101.  
  102.         time[1][Find][k] = GetTickCount();
  103.         for(i=0; i<MAX_VALUE; i++)
  104.             forBu(AB_Iter, i);
  105.         time[1][Find][k] = GetTickCount() - time[1][Find][k];
  106.         Totals[1][Find] += time[1][Find][k];
  107.         //--------------------------------------------------
  108.        
  109.         time[0][Rand][k] = GetTickCount();
  110.         for(i=0; i<MAX_VALUE; i++)
  111.             Iter_Random(YSI_Iter);
  112.         time[0][Rand][k] = GetTickCount() - time[0][Rand][k];
  113.         Totals[0][Rand] += time[0][Rand][k];
  114.  
  115.         time[1][Rand][k] = GetTickCount();
  116.         for(i=0; i<MAX_VALUE; i++)
  117.             forAz(AB_Iter);
  118.         time[1][Rand][k] = GetTickCount() - time[1][Rand][k];
  119.         Totals[1][Rand] += time[1][Rand][k];
  120.         //--------------------------------------------------
  121.     }
  122.    
  123.     #if defined USE_FILE
  124.         fwrite(fHnd, "\r\nAsignacion:\r\n");
  125.         format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Alloc]/MAX_VALUE2, Totals[1][Alloc]/MAX_VALUE2);
  126.         fwrite(fHnd, str);
  127.         fwrite(fHnd, "\r\nRecorrido::\r\n");
  128.         format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][For]/MAX_VALUE2, Totals[1][For]/MAX_VALUE2);
  129.         fwrite(fHnd, str);
  130.         fwrite(fHnd, "\r\nEliminacion:\r\n");
  131.         format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Delete]/MAX_VALUE2, Totals[1][Delete]/MAX_VALUE2);
  132.         fwrite(fHnd, str);
  133.         fwrite(fHnd, "\r\nBusqueda:\r\n");
  134.         format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Find]/MAX_VALUE2, Totals[1][Find]/MAX_VALUE2);
  135.         fwrite(fHnd, str);
  136.         fwrite(fHnd, "\r\nRandom:\r\n");
  137.         format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Rand]/MAX_VALUE2, Totals[1][Rand]/MAX_VALUE2);
  138.         fwrite(fHnd, str);
  139.         fclose(fHnd);
  140.     #else
  141.         printf("\nAsignacion::");
  142.         printf("YSI: %dms\na_Bucles: %dms", Totals[0][Alloc]/MAX_VALUE2, Totals[1][Alloc]/MAX_VALUE2);
  143.         printf("\nRecorrido:");
  144.         printf("YSI: %dms\na_Bucles: %dms", Totals[0][For]/MAX_VALUE2, Totals[1][For]/MAX_VALUE2);
  145.         printf("\nEliminacion:");
  146.         printf("YSI: %dms\na_Bucles: %dms", Totals[0][Delete]/MAX_VALUE2, Totals[1][Delete]/MAX_VALUE2);
  147.         printf("\nBusqueda:");
  148.         printf("YSI: %dms\na_Bucles: %dms", Totals[0][Find]/MAX_VALUE2, Totals[1][Find]/MAX_VALUE2);
  149.         printf("\nRandom:");
  150.         printf("YSI: %dms\na_Bucles: %dms", Totals[0][Rand]/MAX_VALUE2, Totals[1][Rand]/MAX_VALUE2);
  151.     #endif
  152.  
  153.     return 1;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement