Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benchmarks used to test a C and C++ allocator?

Please kindly advise on benchmarks used to test a C and C++ allocator? Benchmarks satisfying any of the following aspects are considered:

  1. Speed
  2. Fragmentation
  3. Concurrency

Thanks!

like image 377
Viet Avatar asked Apr 01 '10 11:04

Viet


2 Answers

I tested several allocators myself a few years ago and my experience is that the results all depend on the kind of test. If you want to write some benchmarks yourself, consider the following situations:

  • allocate lots of memory of a single size, then free it all
  • allocate lots of memory of different sizes, then free it all
  • allocate only a few blocks of memory, free them, and repeat this loop several times (repeat for same-sized blocks and different-sized blocks)
  • allocate lots of memory of different sizes, free half of it (e.g. the even allocations), then allocate and free memory in a loop
  • use two threads to allocate memory in parallel
  • use three, four, five, ... threads to allocate memory in parallel

You will notice that the results will be different for every test. Allocators that are very good in one situation, may be bad in other situations.

In practice this means that it's best to test it in your application, in a live/realistic situation.

like image 188
Patrick Avatar answered Oct 26 '22 18:10

Patrick


You can download nedmalloc and try to compare your allocator with it. It has a test called test.c with the source code, which you can rewrite according to your allocator.

like image 41
Khaled Alshaya Avatar answered Oct 26 '22 18:10

Khaled Alshaya