Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma dynamic 200000
- #include <a_samp>
- #include <YSI\y_malloc>
- #define BENCHMARK_CYCLE (4)
- #define BENCHMARK_LOOP (100000)
- public OnFilterScriptInit()
- {
- print("\n===============================");
- print("= y_malloc.inc benchmark test =");
- print("= Made by BigETI =");
- print("= Loaded =");
- print("===============================\n");
- new i, j, a, b, Alloc:test_mem[BENCHMARK_LOOP], Alloc:new_mem, dummy, dummy_arr[4];
- printf(" y_malloc.inc 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: malloc()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = malloc(1);
- b = GetTickCount();
- printf(" malloc() = %d ms", b-a);
- printf(" %d. test: free()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) free(test_mem[i]);
- b = GetTickCount();
- printf(" free() = %d ms", b-a);
- printf(" %d. test: calloc()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) test_mem[i] = calloc(1);
- b = GetTickCount();
- printf(" calloc() = %d ms", b-a);
- for(j = 0; j < BENCHMARK_LOOP; j++) free(test_mem[i]);
- if((new_mem = malloc(4)))
- {
- printf(" %d. test: mset()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) mset(new_mem, 0, 0xFF);
- b = GetTickCount();
- printf(" mset() = %d ms", b-a);
- printf(" %d. test: mget()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) dummy = mget(new_mem, 0);
- b = GetTickCount();
- #pragma unused dummy
- printf(" mget() = %d ms", b-a);
- printf(" %d. test: msets()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) msets(new_mem, 0, "foo");
- b = GetTickCount();
- printf(" msets() = %d ms", b-a);
- printf(" %d. test: mgets()", i+1);
- a = GetTickCount();
- for(j = 0; j < BENCHMARK_LOOP; j++) mgets(dummy_arr, sizeof dummy_arr, new_mem, 0);
- b = GetTickCount();
- printf(" mgets() = %d ms", b-a);
- free(new_mem);
- }
- else print(" Failed to allocate memory for testing. Benchmark test will be stopped!");
- }
- printf(" y_malloc.inc benchmark test finished!");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("\n===============================");
- print("= y_malloc.inc benchmark test =");
- print("= Made by BigETI =");
- print("= Unloaded =");
- print("===============================\n");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement