Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <foreach>
- #include <a_inc>
- include>a_bucles;
- #include <a_inc2>
- enum TIME_ENUM
- {
- Alloc,
- For,
- Delete,
- Find,
- Rand
- };
- #define USE_FILE
- #define MAX_VALUE (500)
- #define MAX_VALUE2 (15)
- new
- Iterator:YSI_Iter<MAX_VALUE>;
- public OnFilterScriptInit()
- {
- new
- i,
- tmp,
- time[2][TIME_ENUM][MAX_VALUE2],
- Totals[2][TIME_ENUM],
- #if defined USE_FILE
- File:fHnd,
- str[32],
- #endif
- Bucle:AB_Iter<MAX_VALUE>;
- #if defined USE_FILE
- fHnd = fopen("a_bucles speedtest.txt", io_write);
- format(str, 32, "Items: %d(%d)\r\n", MAX_VALUE, MAX_VALUE2);
- fwrite(fHnd, str);
- #else
- printf("Items: %d(%d)", MAX_VALUE, MAX_VALUE2);
- #endif
- for(new k; k<MAX_VALUE2; k++)
- {
- Iter_Clear(YSI_Iter);
- forLi(AB_Iter);
- time[0][Alloc][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- Iter_Add(YSI_Iter, i);
- time[0][Alloc][k] = GetTickCount() - time[0][Alloc][k];
- Totals[0][Alloc] += time[0][Alloc][k];
- time[1][Alloc][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- forAg(AB_Iter, i);
- time[1][Alloc][k] = GetTickCount() - time[1][Alloc][k];
- Totals[1][Alloc] += time[1][Alloc][k];
- //--------------------------------------------------
- time[0][For][k] = GetTickCount();
- tmp = 0;
- foreach(i:YSI_Iter)
- tmp += i;
- time[0][For][k] = GetTickCount() - time[0][For][k];
- Totals[0][For] += time[0][For][k];
- time[1][For][k] = GetTickCount();
- tmp = 0;
- forEach(j,AB_Iter)
- tmp += j;
- time[1][For][k] = GetTickCount() - time[1][For][k];
- Totals[1][For] += time[1][For][k];
- //--------------------------------------------------
- time[0][Delete][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- Iter_Remove(YSI_Iter, i);
- time[0][Delete][k] = GetTickCount() - time[0][Delete][k];
- Totals[0][Delete] += time[0][Delete][k];
- time[1][Delete][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- forEl(AB_Iter, i);
- time[1][Delete][k] = GetTickCount() - time[1][Delete][k];
- Totals[1][Delete] += time[1][Delete][k];
- //--------------------------------------------------
- for(i=0; i<MAX_VALUE; i+=2)
- Iter_Add(YSI_Iter, i);
- for(i=0; i<MAX_VALUE; i+=2)
- forAg(AB_Iter, i);
- time[0][Find][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- Iter_Contains(YSI_Iter, i);
- time[0][Find][k] = GetTickCount() - time[0][Find][k];
- Totals[0][Find] += time[0][Find][k];
- time[1][Find][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- forBu(AB_Iter, i);
- time[1][Find][k] = GetTickCount() - time[1][Find][k];
- Totals[1][Find] += time[1][Find][k];
- //--------------------------------------------------
- time[0][Rand][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- Iter_Random(YSI_Iter);
- time[0][Rand][k] = GetTickCount() - time[0][Rand][k];
- Totals[0][Rand] += time[0][Rand][k];
- time[1][Rand][k] = GetTickCount();
- for(i=0; i<MAX_VALUE; i++)
- forAz(AB_Iter);
- time[1][Rand][k] = GetTickCount() - time[1][Rand][k];
- Totals[1][Rand] += time[1][Rand][k];
- //--------------------------------------------------
- }
- #if defined USE_FILE
- fwrite(fHnd, "\r\nAsignacion:\r\n");
- format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Alloc]/MAX_VALUE2, Totals[1][Alloc]/MAX_VALUE2);
- fwrite(fHnd, str);
- fwrite(fHnd, "\r\nRecorrido::\r\n");
- format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][For]/MAX_VALUE2, Totals[1][For]/MAX_VALUE2);
- fwrite(fHnd, str);
- fwrite(fHnd, "\r\nEliminacion:\r\n");
- format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Delete]/MAX_VALUE2, Totals[1][Delete]/MAX_VALUE2);
- fwrite(fHnd, str);
- fwrite(fHnd, "\r\nBusqueda:\r\n");
- format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Find]/MAX_VALUE2, Totals[1][Find]/MAX_VALUE2);
- fwrite(fHnd, str);
- fwrite(fHnd, "\r\nRandom:\r\n");
- format(str, 32, "YSI: %dms\r\na_Bucles: %dms\r\n", Totals[0][Rand]/MAX_VALUE2, Totals[1][Rand]/MAX_VALUE2);
- fwrite(fHnd, str);
- fclose(fHnd);
- #else
- printf("\nAsignacion::");
- printf("YSI: %dms\na_Bucles: %dms", Totals[0][Alloc]/MAX_VALUE2, Totals[1][Alloc]/MAX_VALUE2);
- printf("\nRecorrido:");
- printf("YSI: %dms\na_Bucles: %dms", Totals[0][For]/MAX_VALUE2, Totals[1][For]/MAX_VALUE2);
- printf("\nEliminacion:");
- printf("YSI: %dms\na_Bucles: %dms", Totals[0][Delete]/MAX_VALUE2, Totals[1][Delete]/MAX_VALUE2);
- printf("\nBusqueda:");
- printf("YSI: %dms\na_Bucles: %dms", Totals[0][Find]/MAX_VALUE2, Totals[1][Find]/MAX_VALUE2);
- printf("\nRandom:");
- printf("YSI: %dms\na_Bucles: %dms", Totals[0][Rand]/MAX_VALUE2, Totals[1][Rand]/MAX_VALUE2);
- #endif
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement