]>
git.proxmox.com Git - rustc.git/blob - src/jemalloc/test/stress/microbench.c
1 #include "test/jemalloc_test.h"
4 time_func(timedelta_t
*timer
, uint64_t nwarmup
, uint64_t niter
, void (*func
)(void))
8 for (i
= 0; i
< nwarmup
; i
++)
11 for (i
= 0; i
< niter
; i
++)
17 compare_funcs(uint64_t nwarmup
, uint64_t niter
, const char *name_a
,
18 void (*func_a
), const char *name_b
, void (*func_b
))
20 timedelta_t timer_a
, timer_b
;
26 test_fail("Unexpected mallocx() failure");
30 time_func(&timer_a
, nwarmup
, niter
, func_a
);
31 time_func(&timer_b
, nwarmup
, niter
, func_b
);
33 timer_ratio(&timer_a
, &timer_b
, ratio_buf
, sizeof(ratio_buf
));
34 malloc_printf("%"FMTu64
" iterations, %s=%"FMTu64
"us, "
35 "%s=%"FMTu64
"us, ratio=1:%s\n",
36 niter
, name_a
, timer_usec(&timer_a
), name_b
, timer_usec(&timer_b
),
45 /* The compiler can optimize away free(malloc(1))! */
48 test_fail("Unexpected malloc() failure");
57 void *p
= mallocx(1, 0);
59 test_fail("Unexpected mallocx() failure");
65 TEST_BEGIN(test_malloc_vs_mallocx
)
68 compare_funcs(10*1000*1000, 100*1000*1000, "malloc",
69 malloc_free
, "mallocx", mallocx_free
);
78 test_fail("Unexpected malloc() failure");
89 test_fail("Unexpected malloc() failure");
95 TEST_BEGIN(test_free_vs_dallocx
)
98 compare_funcs(10*1000*1000, 100*1000*1000, "free", malloc_free
,
99 "dallocx", malloc_dallocx
);
103 TEST_BEGIN(test_dallocx_vs_sdallocx
)
106 compare_funcs(10*1000*1000, 100*1000*1000, "dallocx", malloc_dallocx
,
107 "sdallocx", malloc_sdallocx
);
112 malloc_mus_free(void)
118 test_fail("Unexpected malloc() failure");
121 malloc_usable_size(p
);
126 malloc_sallocx_free(void)
132 test_fail("Unexpected malloc() failure");
135 if (sallocx(p
, 0) < 1)
136 test_fail("Unexpected sallocx() failure");
140 TEST_BEGIN(test_mus_vs_sallocx
)
143 compare_funcs(10*1000*1000, 100*1000*1000, "malloc_usable_size",
144 malloc_mus_free
, "sallocx", malloc_sallocx_free
);
149 malloc_nallocx_free(void)
155 test_fail("Unexpected malloc() failure");
158 if (nallocx(1, 0) < 1)
159 test_fail("Unexpected nallocx() failure");
163 TEST_BEGIN(test_sallocx_vs_nallocx
)
166 compare_funcs(10*1000*1000, 100*1000*1000, "sallocx",
167 malloc_sallocx_free
, "nallocx", malloc_nallocx_free
);
176 test_malloc_vs_mallocx
,
177 test_free_vs_dallocx
,
178 test_dallocx_vs_sdallocx
,
180 test_sallocx_vs_nallocx
));