server-skynet-source-3rd-je.../test/stress/microbench.c

133 lines
2.4 KiB
C
Raw Normal View History

2014-09-08 10:58:04 +08:00
#include "test/jemalloc_test.h"
2020-04-29 03:18:36 +08:00
#include "test/bench.h"
2014-09-08 10:58:04 +08:00
static void
malloc_free(void) {
/* The compiler can optimize away free(malloc(1))! */
void *p = malloc(1);
if (p == NULL) {
test_fail("Unexpected malloc() failure");
return;
}
2022-12-16 02:54:33 +08:00
p = no_opt_ptr(p);
free(p);
2014-09-08 10:58:04 +08:00
}
static void
mallocx_free(void) {
void *p = mallocx(1, 0);
if (p == NULL) {
test_fail("Unexpected mallocx() failure");
return;
}
2022-12-16 02:54:33 +08:00
p = no_opt_ptr(p);
free(p);
2014-09-08 10:58:04 +08:00
}
TEST_BEGIN(test_malloc_vs_mallocx) {
2014-09-08 10:58:04 +08:00
compare_funcs(10*1000*1000, 100*1000*1000, "malloc",
malloc_free, "mallocx", mallocx_free);
2014-09-08 10:58:04 +08:00
}
TEST_END
static void
malloc_dallocx(void) {
void *p = malloc(1);
if (p == NULL) {
test_fail("Unexpected malloc() failure");
return;
}
2022-12-16 02:54:33 +08:00
p = no_opt_ptr(p);
dallocx(p, 0);
2014-09-08 10:58:04 +08:00
}
static void
malloc_sdallocx(void) {
void *p = malloc(1);
if (p == NULL) {
test_fail("Unexpected malloc() failure");
return;
}
2022-12-16 02:54:33 +08:00
p = no_opt_ptr(p);
sdallocx(p, 1, 0);
}
TEST_BEGIN(test_free_vs_dallocx) {
compare_funcs(10*1000*1000, 100*1000*1000, "free", malloc_free,
"dallocx", malloc_dallocx);
2014-09-08 10:58:04 +08:00
}
TEST_END
TEST_BEGIN(test_dallocx_vs_sdallocx) {
compare_funcs(10*1000*1000, 100*1000*1000, "dallocx", malloc_dallocx,
"sdallocx", malloc_sdallocx);
}
TEST_END
2014-09-08 10:58:04 +08:00
static void
malloc_mus_free(void) {
2014-09-08 10:58:04 +08:00
void *p;
p = malloc(1);
2014-10-16 05:49:14 +08:00
if (p == NULL) {
test_fail("Unexpected malloc() failure");
return;
}
TEST_MALLOC_SIZE(p);
2014-09-08 10:58:04 +08:00
free(p);
}
static void
malloc_sallocx_free(void) {
2014-09-08 10:58:04 +08:00
void *p;
p = malloc(1);
2014-10-16 05:49:14 +08:00
if (p == NULL) {
test_fail("Unexpected malloc() failure");
return;
}
2022-12-16 02:54:33 +08:00
p = no_opt_ptr(p);
if (sallocx(p, 0) < 1) {
test_fail("Unexpected sallocx() failure");
}
2014-09-08 10:58:04 +08:00
free(p);
}
TEST_BEGIN(test_mus_vs_sallocx) {
2014-09-08 10:58:04 +08:00
compare_funcs(10*1000*1000, 100*1000*1000, "malloc_usable_size",
malloc_mus_free, "sallocx", malloc_sallocx_free);
2014-09-08 10:58:04 +08:00
}
TEST_END
static void
malloc_nallocx_free(void) {
2014-09-08 10:58:04 +08:00
void *p;
p = malloc(1);
2014-10-16 05:49:14 +08:00
if (p == NULL) {
test_fail("Unexpected malloc() failure");
return;
}
2022-12-16 02:54:33 +08:00
p = no_opt_ptr(p);
if (nallocx(1, 0) < 1) {
test_fail("Unexpected nallocx() failure");
}
2014-09-08 10:58:04 +08:00
free(p);
}
TEST_BEGIN(test_sallocx_vs_nallocx) {
2014-09-08 10:58:04 +08:00
compare_funcs(10*1000*1000, 100*1000*1000, "sallocx",
malloc_sallocx_free, "nallocx", malloc_nallocx_free);
2014-09-08 10:58:04 +08:00
}
TEST_END
int
main(void) {
return test_no_reentrancy(
2014-09-08 10:58:04 +08:00
test_malloc_vs_mallocx,
test_free_vs_dallocx,
test_dallocx_vs_sdallocx,
2014-09-08 10:58:04 +08:00
test_mus_vs_sallocx,
test_sallocx_vs_nallocx);
2014-09-08 10:58:04 +08:00
}