mirror of
https://github.com/gperftools/gperftools
synced 2024-12-23 15:52:10 +00:00
64e0133901
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.
94 lines
1.1 KiB
C++
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;
|
|
}
|