Squashed 'third_party/gperftools/' content from commit 54505f1
Change-Id: Id02e833828732b0efe7dac722b8485279e67c5fa
git-subtree-dir: third_party/gperftools
git-subtree-split: 54505f1d50c2d1f4676f5e87090b64a117fd980e
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;
+}