TL;DR: We can speed up timestamps on x86 Linux by 30% and maintain the same precision as the standard system clock by implementing our own timers without relying on vDSO. Almost nobody should do this. Table of contents Timing the timers The TSC When syscalls aren’t Faster monotonic clocks Making our own vDSO Measuring tails Stable timers Conclusion Appendix: Methodology Timing the timers One of my…
Table of contents Introduction Case 1: Modular increment The scenario Peephole optimisations Loop invariants All roads Case 2: Endianness conversion The scenario Instruction selection Helping the compiler Ordering, redux Shooting ourselves in the foot Conclusion Appendix: other resources Introduction While many performance-oriented programmers are intimately acquainted with the almost…
A tale of three functions The year is 2005. As part of a parser utility library at your job, you write the following function to read a known-size list of formatted values from a stream into a vector: template < typename T > static std :: vector < T > read_vector ( std :: istream & is , std :: size_t size ) { std :: vector < T > out ; T val ; while ( size -- && is >> val ) { out . push_back ( val…
A few years back, some time after the Wordle craze abated, I found a new word game called Waffle and promptly got hooked. If you’ve never played it before, I highly recommend trying it out before reading the rest of this post. Waffle 101 Waffle, created by James Robinson, is a sort of crossword-shaped jigsaw puzzle with 21 letters in a five by five grid. The goal is to reconstruct the six original…