gperftools/benchmark/malloc_bench.cc
Aliaksey Kandratsenka 64e0133901 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.
2015-08-02 16:53:19 -07:00

94 lines
1.1 KiB
C++

#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;
}