Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma dynamic 200000
- #include <a_samp>
- #include <memory>
- #define BENCHMARK_CYCLE (4)
- #define BENCHMARK_LOOP (100000)
- public OnFilterScriptInit()
- {
- print("\n=======================================");
- print("= Memory access plugin benchmark test =");
- print("= Made by BigETI =");
- print("= Loaded =");
- print("=======================================\n");
- new i, j, a, b, Pointer:test_mem[BENCHMARK_LOOP], Pointer:new_mem, dummy, dummy_arr[4];
- printf(" Memory access plugin benchmark test will be done %d times and each function will be tested %d times.", BENCHMARK_CYCLE, BENCHMARK_LOOP);
- for(i = 0; i < BENCHMARK_CYCLE; i++)
- {
- printf(" %d. test: MEM::malloc()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = MEM::malloc(1);
- b = GetTickCount();
- printf(" MEM::malloc() = %d ms", b-a);
- printf(" %d. test: MEM::free()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) MEM::free(test_mem[i]);
- b = GetTickCount();
- printf(" MEM::free() = %d ms", b-a);
- printf(" %d. test: MEM::calloc()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = MEM::calloc(1);
- b = GetTickCount();
- printf(" MEM::calloc() = %d ms", b-a);
- for(j = 0; j < BENCHMARK_LOOP; j++) MEM::free(test_mem[i]);
- if((new_mem = MEM::malloc(4)))
- {
- printf(" %d. test: MEM::set_val()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) MEM::set_val(new_mem, _, 0xFF);
- b = GetTickCount();
- printf(" MEM::set_val() = %d ms", b-a);
- printf(" %d. test: MEM::get_val()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) dummy = MEM::get_val(new_mem, 0);
- b = GetTickCount();
- #pragma unused dummy
- printf(" MEM::get_val() = %d ms", b-a);
- printf(" %d. test: MEM::set_arr()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) MEM::set_arr(new_mem, _, "foo", 4);
- b = GetTickCount();
- printf(" MEM::set_arr() = %d ms", b-a);
- printf(" %d. test: MEM::get_arr()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) MEM::get_arr(new_mem, _, dummy_arr);
- b = GetTickCount();
- printf(" MEM::get_arr() = %d ms", b-a);
- MEM::free(new_mem);
- }
- else print(" Failed to allocate memory for testing. Benchmark test will be stopped!");
- }
- printf(" Memory access plugin benchmark test finished!");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("\n=======================================");
- print("= Memory access plugin benchmark test =");
- print("= Made by BigETI =");
- print("= Unloaded =");
- print("=======================================\n");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement