dispatch_benchmark(3)
π dispatch_benchmark β the vibe check for your code's speed π
okay so bestie, we're in the dispatch_benchmark(3) page from the Library Functions Manual πΈ and it's literally just here to tell you how fast your blocks are running. no cap.
β¨ NAME β¨
dispatch_benchmark β Measures block execution time β±οΈ
π SYNOPSIS π
#include <dispatch/dispatch.h>
uint64_t
dispatch_benchmark(size_t count, void (^block)(void));
uint64_t
dispatch_benchmark_f(size_t count, void *context,
void (*function)(void *));
π DESCRIPTION π
so the dispatch_benchmark() function takes your block and runs it over and over β however many times count says β and then hands you back the average number of nanoseconds per execution. that's it, that's the whole gig π«Ά
this one is for debugging and performance analysis work. like, it's giving lab coat energy, not production energy, yk?
for the best results, pass a high count value to dispatch_benchmark(). lowkey obvious but they said it so we're saying it β¨
now, when you're benchmarking concurrent code, here's the tea π΅:
- compare the serial version of the code against the concurrent version
- compare the concurrent version on different classes of hardware
- look for inflection points with various data sets
and keep these facts in mind, periodt:
- Code bound by computational bandwidth may be inferred by proportional changes in performance as concurrency is increased. π
- Code bound by memory bandwidth may be inferred by negligible changes in performance as concurrency is increased. π
- Code bound by critical sections may be inferred by retrograde changes in performance as concurrency is increased. π
- Intentional: locks, mutexes, and condition variables. π
- Accidental: unrelated and frequently modified data on the same cache-line. π
bestie. the accidental one is the one that gets you. same cache-line, unrelated data, constantly getting touched?? that's not a bug, that's a crime scene π
π RETURN VALUE π
The dispatch_benchmark() function returns the average number of nanoseconds the given block takes to execute. that's your number, that's your truth, go off π
π SEE ALSO π
and that's the whole page, babe π¦ it's from Darwin, dated May 1, 2009 β yeah, 2009, this one's been iconic since before some of us could read π stay fast, stay benchmarked, mwah π
π¦ where this page comes from
- ubuntu jammy: libdispatch-dev 0~svn197-3.3ubuntu2
- Copyright (c) 2008-2009 Apple Inc. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms