Advertisement
BigETI

y_malloc_benchmark.pwn

Jul 16th, 2013
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.50 KB | None | 0 0
  1. #pragma dynamic 200000
  2. #include <a_samp>
  3. #include <YSI\y_malloc>
  4.  
  5. #define BENCHMARK_CYCLE (4)
  6. #define BENCHMARK_LOOP  (100000)
  7.  
  8. public OnFilterScriptInit()
  9. {
  10.     print("\n===============================");
  11.     print("= y_malloc.inc benchmark test =");
  12.     print("=              Made by BigETI =");
  13.     print("= Loaded                      =");
  14.     print("===============================\n");
  15.    
  16.     new i, j, a, b, Alloc:test_mem[BENCHMARK_LOOP], Alloc:new_mem, dummy, dummy_arr[4];
  17.     printf(" y_malloc.inc benchmark test will be done %d times and each function will be tested %d times.", BENCHMARK_CYCLE, BENCHMARK_LOOP);
  18.     for(i = 0; i < BENCHMARK_CYCLE; i++)
  19.     {
  20.         printf(" %d. test: malloc()", i+1);
  21.         a = GetTickCount();
  22.         for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = malloc(1);
  23.         b = GetTickCount();
  24.         printf(" malloc() = %d ms", b-a);
  25.         printf(" %d. test: free()", i+1);
  26.         a = GetTickCount();
  27.         for(j = 0; j < BENCHMARK_LOOP; j++) free(test_mem[i]);
  28.         b = GetTickCount();
  29.         printf(" free() = %d ms", b-a);
  30.         printf(" %d. test: calloc()", i+1);
  31.         a = GetTickCount();
  32.         for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = calloc(1);
  33.         b = GetTickCount();
  34.         printf(" calloc() = %d ms", b-a);
  35.         for(j = 0; j < BENCHMARK_LOOP; j++) free(test_mem[i]);
  36.         if((new_mem = malloc(4)))
  37.         {
  38.             printf(" %d. test: mset()", i+1);
  39.             a = GetTickCount();
  40.             for(j = 0; j < BENCHMARK_LOOP; j++) mset(new_mem, 0, 0xFF);
  41.             b = GetTickCount();
  42.             printf(" mset() = %d ms", b-a);
  43.             printf(" %d. test: mget()", i+1);
  44.             a = GetTickCount();
  45.             for(j = 0; j < BENCHMARK_LOOP; j++) dummy = mget(new_mem, 0);
  46.             b = GetTickCount();
  47. #pragma unused  dummy
  48.             printf(" mget() = %d ms", b-a);
  49.             printf(" %d. test: msets()", i+1);
  50.             a = GetTickCount();
  51.             for(j = 0; j < BENCHMARK_LOOP; j++) msets(new_mem, 0, "foo");
  52.             b = GetTickCount();
  53.             printf(" msets() = %d ms", b-a);
  54.             printf(" %d. test: mgets()", i+1);
  55.             a = GetTickCount();
  56.             for(j = 0; j < BENCHMARK_LOOP; j++) mgets(dummy_arr, sizeof dummy_arr, new_mem, 0);
  57.             b = GetTickCount();
  58.             printf(" mgets() = %d ms", b-a);
  59.             free(new_mem);
  60.         }
  61.         else print(" Failed to allocate memory for testing. Benchmark test will be stopped!");
  62.     }
  63.     printf(" y_malloc.inc benchmark test finished!");
  64.     return 1;
  65. }
  66.  
  67. public OnFilterScriptExit()
  68. {
  69.     print("\n===============================");
  70.     print("= y_malloc.inc benchmark test =");
  71.     print("=              Made by BigETI =");
  72.     print("= Unloaded                    =");
  73.     print("===============================\n");
  74.     return 1;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement