dispatch_benchmark(3)

πŸ“¦ version 0~svn197, in ubuntu jammy

πŸ’– 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