summaryrefslogtreecommitdiffstats
path: root/test/stress/microbench.c
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2017-06-13 19:49:58 (GMT)
committerJason Evans <jasone@canonware.com>2017-06-13 19:51:09 (GMT)
commit5018fe3f0979b7f9db9930accdf7ee31071fd703 (patch)
tree894055b5ff4ccde3d9d782861d45af4664f12ad2 /test/stress/microbench.c
parent04380e79f1e2428bd0ad000bbc6e3d2dfc6b66a5 (diff)
parentba29113e5a58caeb6b4a65b1db6d8efae79cae45 (diff)
downloadjemalloc-5.0.0.zip
jemalloc-5.0.0.tar.gz
jemalloc-5.0.0.tar.bz2
Merge branch 'dev'5.0.0
Diffstat (limited to 'test/stress/microbench.c')
-rw-r--r--test/stress/microbench.c69
1 files changed, 26 insertions, 43 deletions
diff --git a/test/stress/microbench.c b/test/stress/microbench.c
index 7dc45f8..988b793 100644
--- a/test/stress/microbench.c
+++ b/test/stress/microbench.c
@@ -1,23 +1,23 @@
#include "test/jemalloc_test.h"
-JEMALLOC_INLINE_C void
+static inline void
time_func(timedelta_t *timer, uint64_t nwarmup, uint64_t niter,
- void (*func)(void))
-{
+ void (*func)(void)) {
uint64_t i;
- for (i = 0; i < nwarmup; i++)
+ for (i = 0; i < nwarmup; i++) {
func();
+ }
timer_start(timer);
- for (i = 0; i < niter; i++)
+ for (i = 0; i < niter; i++) {
func();
+ }
timer_stop(timer);
}
void
compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
- void (*func_a), const char *name_b, void (*func_b))
-{
+ void (*func_a), const char *name_b, void (*func_b)) {
timedelta_t timer_a, timer_b;
char ratio_buf[6];
void *p;
@@ -41,8 +41,7 @@ compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
}
static void
-malloc_free(void)
-{
+malloc_free(void) {
/* The compiler can optimize away free(malloc(1))! */
void *p = malloc(1);
if (p == NULL) {
@@ -53,8 +52,7 @@ malloc_free(void)
}
static void
-mallocx_free(void)
-{
+mallocx_free(void) {
void *p = mallocx(1, 0);
if (p == NULL) {
test_fail("Unexpected mallocx() failure");
@@ -63,17 +61,14 @@ mallocx_free(void)
free(p);
}
-TEST_BEGIN(test_malloc_vs_mallocx)
-{
-
+TEST_BEGIN(test_malloc_vs_mallocx) {
compare_funcs(10*1000*1000, 100*1000*1000, "malloc",
malloc_free, "mallocx", mallocx_free);
}
TEST_END
static void
-malloc_dallocx(void)
-{
+malloc_dallocx(void) {
void *p = malloc(1);
if (p == NULL) {
test_fail("Unexpected malloc() failure");
@@ -83,8 +78,7 @@ malloc_dallocx(void)
}
static void
-malloc_sdallocx(void)
-{
+malloc_sdallocx(void) {
void *p = malloc(1);
if (p == NULL) {
test_fail("Unexpected malloc() failure");
@@ -93,25 +87,20 @@ malloc_sdallocx(void)
sdallocx(p, 1, 0);
}
-TEST_BEGIN(test_free_vs_dallocx)
-{
-
+TEST_BEGIN(test_free_vs_dallocx) {
compare_funcs(10*1000*1000, 100*1000*1000, "free", malloc_free,
"dallocx", malloc_dallocx);
}
TEST_END
-TEST_BEGIN(test_dallocx_vs_sdallocx)
-{
-
+TEST_BEGIN(test_dallocx_vs_sdallocx) {
compare_funcs(10*1000*1000, 100*1000*1000, "dallocx", malloc_dallocx,
"sdallocx", malloc_sdallocx);
}
TEST_END
static void
-malloc_mus_free(void)
-{
+malloc_mus_free(void) {
void *p;
p = malloc(1);
@@ -124,8 +113,7 @@ malloc_mus_free(void)
}
static void
-malloc_sallocx_free(void)
-{
+malloc_sallocx_free(void) {
void *p;
p = malloc(1);
@@ -133,22 +121,20 @@ malloc_sallocx_free(void)
test_fail("Unexpected malloc() failure");
return;
}
- if (sallocx(p, 0) < 1)
+ if (sallocx(p, 0) < 1) {
test_fail("Unexpected sallocx() failure");
+ }
free(p);
}
-TEST_BEGIN(test_mus_vs_sallocx)
-{
-
+TEST_BEGIN(test_mus_vs_sallocx) {
compare_funcs(10*1000*1000, 100*1000*1000, "malloc_usable_size",
malloc_mus_free, "sallocx", malloc_sallocx_free);
}
TEST_END
static void
-malloc_nallocx_free(void)
-{
+malloc_nallocx_free(void) {
void *p;
p = malloc(1);
@@ -156,27 +142,24 @@ malloc_nallocx_free(void)
test_fail("Unexpected malloc() failure");
return;
}
- if (nallocx(1, 0) < 1)
+ if (nallocx(1, 0) < 1) {
test_fail("Unexpected nallocx() failure");
+ }
free(p);
}
-TEST_BEGIN(test_sallocx_vs_nallocx)
-{
-
+TEST_BEGIN(test_sallocx_vs_nallocx) {
compare_funcs(10*1000*1000, 100*1000*1000, "sallocx",
malloc_sallocx_free, "nallocx", malloc_nallocx_free);
}
TEST_END
int
-main(void)
-{
-
- return (test(
+main(void) {
+ return test_no_reentrancy(
test_malloc_vs_mallocx,
test_free_vs_dallocx,
test_dallocx_vs_sdallocx,
test_mus_vs_sallocx,
- test_sallocx_vs_nallocx));
+ test_sallocx_vs_nallocx);
}