summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alk@tut.by>2015-05-03 12:55:47 -0700
committerAliaksey Kandratsenka <alk@tut.by>2015-08-02 16:53:19 -0700
commit64e0133901a20f83c41adb36748fd19d21228515 (patch)
tree86d91f813f7c800fc00d4027419d1bc9170b0ead
parente1d1311cfb6312cd44e086c879f3e95cbfa0eb9d (diff)
downloadgperftools-64e0133901a20f83c41adb36748fd19d21228515.tar.gz
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.
-rw-r--r--.gitignore6
-rwxr-xr-xMakefile.am12
-rw-r--r--benchmark/malloc_bench.cc93
3 files changed, 111 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 3e74f99..055a09d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Makefile.am b/Makefile.am
index a5a9af8..bae605a 100755
--- a/Makefile.am
+++ b/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)
diff --git a/benchmark/malloc_bench.cc b/benchmark/malloc_bench.cc
new file mode 100644
index 0000000..e5e0d38
--- /dev/null
+++ b/benchmark/malloc_bench.cc
@@ -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;
+}