Show HN: Single-Header Profiler for C++17

Morning HN.

I often found myself wondering "how much does this code segment take in terms of total runtime" and it's often quite annoying to figure out with optimizations enabled, especially when working on something new or testing someone else's implementation without the proper tooling set up. Wanted to have a single include lib that would allow us to write something like:

``` PROFILE("Loop 1") for (...) // some work ```

and have the next expression automatically record time & dump results to a table. Wrote a few macros to do exactly that a few months back, but they were primitive and basically unusable for recursive code.

Tried to come up with a more generic solution that would build a call graph for nested profiler-macros, handle threads and etc. but doing so in a naive way would be super slow since we'd need some kind of a recursive map of nodes with callsites as a keys.

Recently had a revelation that it is possible to use macro-generated thread_local's to associate callsites with integer IDs on the fly and with some effort call graph can be neatly encoded in a few contiguous arrays with all graph building & traversal logic reduced to simple checks and array lookups. Realized threading can be quite easily supported too in an almost lock-free fashion.

After a few days of effort ended up building what I believe is a very much usable single-header profiling lib. Couldn't find anything quite like it, so I'd like to present it here and hear some opinions on the product:

https://github.com/DmitriBogdanov/UTL/blob/master/docs/modul...


Comments URL: https://news.ycombinator.com/item?id=43680477

Points: 22

# Comments: 3

https://github.com/DmitriBogdanov/UTL/blob/master/docs/module_profiler.md

Erstellt 1mo | 14.04.2025, 18:10:12


Melden Sie sich an, um einen Kommentar hinzuzufügen

Andere Beiträge in dieser Gruppe

Show HN: Model2vec-Rs – Fast Static Text Embeddings in Rust

Hey HN! We’ve just open-sourced model2vec-rs, a Rust crate for loading and running Model2Vec static embedding models with zero Python dependency. This allows you to embed text at (very) high throu

18.05.2025, 18:10:16 | Hacker news
Show HN: Buckaroo – Data table UI for Notebooks

Buckaroo is my open source project. It is a dataframe viewer that has the basic features we expect in a modern table - scroll, search, sort. In addition there are summary stats, and histograms ava

18.05.2025, 18:10:13 | Hacker news
Show HN: I modeled the Voynich Manuscript with SBERT to test for structure

I built this project as a way to learn more about NLP by applying it to something weird and unsolved.

The Voynich Manuscript is a 15th-century book written in an unknown script. No one’s been ab

18.05.2025, 18:10:11 | Hacker news