added trivial malloc fast-path benchmark
While this is not good representation of real-world production malloc behavior, it is representative of length (instruction-wise and well as cycle-wise) of fast-path. So this is better than nothing.
This commit is contained in:
parent
e1d1311cfb
commit
64e0133901
|
@ -19,6 +19,8 @@
|
|||
/atomicops_unittest
|
||||
/atomicops_unittest.exe
|
||||
/autom4te.cache/
|
||||
/benchmark/.deps
|
||||
/benchmark/.dirstamp
|
||||
/compile
|
||||
/config.guess
|
||||
/config.log
|
||||
|
@ -59,6 +61,10 @@
|
|||
/m4/ltsugar.m4
|
||||
/m4/ltversion.m4
|
||||
/m4/lt~obsolete.m4
|
||||
/malloc_bench
|
||||
/malloc_bench.exe
|
||||
/malloc_bench_shared
|
||||
/malloc_bench_shared.exe
|
||||
/malloc_extension_c_test
|
||||
/malloc_extension_debug_test
|
||||
/malloc_extension_test
|
||||
|
|
12
Makefile.am
12
Makefile.am
|
@ -847,6 +847,18 @@ endif WITH_STACK_TRACE
|
|||
|
||||
endif WITH_DEBUGALLOC
|
||||
|
||||
noinst_PROGRAMS += malloc_bench malloc_bench_shared
|
||||
|
||||
malloc_bench_SOURCES = benchmark/malloc_bench.cc
|
||||
malloc_bench_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS) $(NO_BUILTIN_CXXFLAGS)
|
||||
malloc_bench_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS) -static
|
||||
malloc_bench_LDADD = libtcmalloc_minimal.la $(PTHREAD_LIBS)
|
||||
|
||||
malloc_bench_shared_SOURCES = benchmark/malloc_bench.cc
|
||||
malloc_bench_shared_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS) $(NO_BUILTIN_CXXFLAGS)
|
||||
malloc_bench_shared_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
|
||||
malloc_bench_shared_LDADD = libtcmalloc_minimal.la $(PTHREAD_LIBS)
|
||||
|
||||
|
||||
### ------- tcmalloc (thread-caching malloc + heap profiler + heap checker)
|
||||
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
long long i = 1LL<<(28-4);
|
||||
size_t sz = 32;
|
||||
printf("i = %lld\n", i);
|
||||
for (;i>0;i--) {
|
||||
void *p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
free(p);
|
||||
sz = ((sz | reinterpret_cast<size_t>(p)) & 511) + 16;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue