Advertisement
BigETI

memory_benchmark.pwn

Jul 16th, 2013
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.72 KB | None | 0 0
  1. #pragma dynamic 200000
  2. #include <a_samp>
  3. #include <memory>
  4.  
  5. #define BENCHMARK_CYCLE (4)
  6. #define BENCHMARK_LOOP  (100000)
  7.  
  8. public OnFilterScriptInit()
  9. {
  10.     print("\n=======================================");
  11.     print("= Memory access plugin benchmark test =");
  12.     print("=                      Made by BigETI =");
  13.     print("= Loaded                              =");
  14.     print("=======================================\n");
  15.  
  16.     new i, j, a, b, Pointer:test_mem[BENCHMARK_LOOP], Pointer:new_mem, dummy, dummy_arr[4];
  17.     printf(" Memory access plugin 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: MEM::malloc()", i+1);
  21.         a = GetTickCount();
  22.         for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = MEM::malloc(1);
  23.         b = GetTickCount();
  24.         printf(" MEM::malloc() = %d ms", b-a);
  25.         printf(" %d. test: MEM::free()", i+1);
  26.         a = GetTickCount();
  27.         for(j = 0; j < BENCHMARK_LOOP; j++) MEM::free(test_mem[i]);
  28.         b = GetTickCount();
  29.         printf(" MEM::free() = %d ms", b-a);
  30.         printf(" %d. test: MEM::calloc()", i+1);
  31.         a = GetTickCount();
  32.         for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = MEM::calloc(1);
  33.         b = GetTickCount();
  34.         printf(" MEM::calloc() = %d ms", b-a);
  35.         for(j = 0; j < BENCHMARK_LOOP; j++) MEM::free(test_mem[i]);
  36.         if((new_mem = MEM::malloc(4)))
  37.         {
  38.             printf(" %d. test: MEM::set_val()", i+1);
  39.             a = GetTickCount();
  40.             for(j = 0; j < BENCHMARK_LOOP; j++) MEM::set_val(new_mem, _, 0xFF);
  41.             b = GetTickCount();
  42.             printf(" MEM::set_val() = %d ms", b-a);
  43.             printf(" %d. test: MEM::get_val()", i+1);
  44.             a = GetTickCount();
  45.             for(j = 0; j < BENCHMARK_LOOP; j++) dummy = MEM::get_val(new_mem, 0);
  46.             b = GetTickCount();
  47. #pragma unused  dummy
  48.             printf(" MEM::get_val() = %d ms", b-a);
  49.             printf(" %d. test: MEM::set_arr()", i+1);
  50.             a = GetTickCount();
  51.             for(j = 0; j < BENCHMARK_LOOP; j++) MEM::set_arr(new_mem, _, "foo", 4);
  52.             b = GetTickCount();
  53.             printf(" MEM::set_arr() = %d ms", b-a);
  54.             printf(" %d. test: MEM::get_arr()", i+1);
  55.             a = GetTickCount();
  56.             for(j = 0; j < BENCHMARK_LOOP; j++) MEM::get_arr(new_mem, _, dummy_arr);
  57.             b = GetTickCount();
  58.             printf(" MEM::get_arr() = %d ms", b-a);
  59.             MEM::free(new_mem);
  60.         }
  61.         else print(" Failed to allocate memory for testing. Benchmark test will be stopped!");
  62.     }
  63.     printf(" Memory access plugin benchmark test finished!");
  64.     return 1;
  65. }
  66.  
  67. public OnFilterScriptExit()
  68. {
  69.     print("\n=======================================");
  70.     print("= Memory access plugin 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