// The goal is to create malloc/free interleaving patterns across threads. // The bytes processed by each thread will be the same. The difference is the // patterns. Here's an example: // // A: Allocation // D: Deallocation // // T1 T2 T3 // A A A // A A D // A D A // A D D // D A A // D A D // D D A // D D D // // To do this, `AllocCounts` and `AllocRounds` will be adjusted according to the // thread id. auto thread_task = [&](size_t id) {
{
std::unique_lock lock(m); // Wait until all threads are created.
cv.wait(lock, [&] { return ready; });
}
for (size_t i = 0; i < AllocRounds; ++i) { for (size_t j = 0; j < AllocCounts; ++j) { void* ptr = malloc(size);
MemPool[j] = ptr;
}
// Use a fix seed to reduce the noise of different round of benchmark. constunsigned seed = 33529;
std::shuffle(MemPool, &MemPool[AllocCounts], std::default_random_engine(seed));
// Note that this will only test a single size class at a time so that we can // observe the impact of contention more often. #define BM_MALLOC_THREADS_THROUGHPUT(SIZE, NUM_THREADS) \ staticvoid BM_malloc_threads_throughput_##SIZE##_##NUM_THREADS(benchmark::State& state) { \
RunThreadsThroughput(state, SIZE, NUM_THREADS); \
} \
BIONIC_BENCHMARK(BM_malloc_threads_throughput_##SIZE##_##NUM_THREADS);
// There are three block categories in Scudo, we choose 1 from each category.
BM_MALLOC_THREADS_THROUGHPUT(64, 2);
BM_MALLOC_THREADS_THROUGHPUT(64, 4);
BM_MALLOC_THREADS_THROUGHPUT(64, 8);
BM_MALLOC_THREADS_THROUGHPUT(512, 2);
BM_MALLOC_THREADS_THROUGHPUT(512, 4);
BM_MALLOC_THREADS_THROUGHPUT(512, 8);
BM_MALLOC_THREADS_THROUGHPUT(8192, 2);
BM_MALLOC_THREADS_THROUGHPUT(8192, 4);
BM_MALLOC_THREADS_THROUGHPUT(8192, 8);
#endif
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.