mirror of
https://github.com/gperftools/gperftools
synced 2024-12-22 07:20:01 +00:00
added sized free benchmarks to malloc_bench
This commit is contained in:
parent
71ffc1cd6b
commit
b762b1a492
@ -68,7 +68,7 @@ static void bench_fastpath_dependent(long iterations,
|
||||
static void bench_fastpath_simple(long iterations,
|
||||
uintptr_t param)
|
||||
{
|
||||
size_t sz = 64;
|
||||
size_t sz = static_cast<size_t>(param);
|
||||
for (; iterations>0; iterations--) {
|
||||
void *p = malloc(sz);
|
||||
if (!p) {
|
||||
@ -82,6 +82,35 @@ static void bench_fastpath_simple(long iterations,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define HAVE_SIZED_FREE_OPTION
|
||||
|
||||
extern "C" void tc_free_sized(void *ptr, size_t size) __attribute__((weak));
|
||||
|
||||
static bool is_sized_free_available(void)
|
||||
{
|
||||
return tc_free_sized != NULL;
|
||||
}
|
||||
|
||||
static void bench_fastpath_simple_sized(long iterations,
|
||||
uintptr_t param)
|
||||
{
|
||||
size_t sz = static_cast<size_t>(param);
|
||||
for (; iterations>0; iterations--) {
|
||||
void *p = malloc(sz);
|
||||
if (!p) {
|
||||
abort();
|
||||
}
|
||||
tc_free_sized(p, sz);
|
||||
// next iteration will use same free list as this iteration. So it
|
||||
// should be prevent next iterations malloc to go too far before
|
||||
// free done. But using same size will make free "too fast" since
|
||||
// we'll hit size class cache.
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __GNUC__
|
||||
|
||||
#define STACKSZ (1 << 16)
|
||||
|
||||
static void bench_fastpath_stack(long iterations,
|
||||
@ -213,7 +242,17 @@ int main(void)
|
||||
|
||||
report_benchmark("bench_fastpath_throughput", bench_fastpath_throughput, 0);
|
||||
report_benchmark("bench_fastpath_dependent", bench_fastpath_dependent, 0);
|
||||
report_benchmark("bench_fastpath_simple", bench_fastpath_simple, 0);
|
||||
report_benchmark("bench_fastpath_simple", bench_fastpath_simple, 64);
|
||||
report_benchmark("bench_fastpath_simple", bench_fastpath_simple, 2048);
|
||||
report_benchmark("bench_fastpath_simple", bench_fastpath_simple, 16384);
|
||||
|
||||
#ifdef HAVE_SIZED_FREE_OPTION
|
||||
if (is_sized_free_available()) {
|
||||
report_benchmark("bench_fastpath_simple_sized", bench_fastpath_simple_sized, 64);
|
||||
report_benchmark("bench_fastpath_simple_sized", bench_fastpath_simple_sized, 2048);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 8; i <= 512; i <<= 1) {
|
||||
report_benchmark("bench_fastpath_stack", bench_fastpath_stack, i);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user