Paolo Bietolini

Home | Feed Atom

Making hexdump 23 times faster (and what I've learned)

Last month I wrote hexdump from scratch and admitted I didn’t know a good alternative to printf per row. I found it: one fwrite per 64 KiB chunk instead of 128 million calls into stdio, and a 23× speedup, most of it from the part I thought was boring.

Writing hexdump from scratch

Say we want to inspect a corrupted file. To figure out its real type we can check its signature, the first few bytes of the file. On Unix-like systems, the tool for the job is hexdump: a program that shows the hexadecimal content of a file or of a data stream.