All guides
Every guide, newest first. Browse by topic instead, or read the daily tips and puzzles.
-
C++ STL Containers: vector, map, and set by Example C++
Use the three containers beginners reach for first: vector for an ordered list that grows, map for lookup by name, set for unique values in sorted order.
-
C++ Pointers and References: Addresses, Dereferencing, and nullptr C++
Learn C++ pointers and references by running code: address-of and dereference, why a pointer can be re-pointed and a reference cannot, pass-by-reference, pointer arithmetic on an array, and nullptr. Every number below is the output of a program run.
-
C++ Loops: for, while, do-while, and Range-for C++
The four C++ loop forms: a counted for loop sums 1 to 5 and prints for sum=15, a while loop counts down from 3, a range-for walks a vector of 10, 20, 30 with no index, and a do-while runs once even when its condition starts false. The same programs show break and continue, the off-by-one difference between < and <=, and why a range-for needs a reference to change the values it visits.
-
C++ Functions: Parameters, Overloads, and Default Arguments C++
C++ functions: two add overloads print add int=5 and add double=6, a default argument makes mult(5) print 10 while mult(5, 3) prints 15, and a swap through references prints swapped x=2 y=1. The same code shows why pass-by-value leaves the caller unchanged, why add(2, 3.5) fails to compile as ambiguous, and why a default argument must come last.
-
C++ Exceptions: try, catch, and throw, With the Program Still Running After C++
C++ exceptions: a divide function throws std::runtime_error on a zero divisor and the catch block prints caught: divide by zero, a thrown int is caught as int=42, and the program prints after catch, program continues. The same guide shows a std::vector .at() call throwing std::out_of_range, catch by value slicing a derived exception down to its base, and catch (...) receiving a throw it cannot name.
-
C++ Classes and Objects: Your First Class, Constructor, and Methods C++
Build your first C++ class by running code: a Counter class with a constructor initializer list, methods, const methods, and private members. The program prints hits=3, and every compiler error in the guide is quoted verbatim from a box run.
-
C++ Arrays and std::array: C Arrays, Bounds, and the Safe Replacement C++
C++ arrays: a C array of three ints prints size=3 from the sizeof idiom, a function that receives the array prints inside sizeof=8 because the array decayed to a pointer, and std::array prints b.size=3 and b sum=15. The same code shows std::array::at(5) throwing std::out_of_range, caught and printed, while operator[] does no bounds checking at all.
-
Concurrency, Async, and Waiting: Fifteen Guides on Threads, Coroutines, and Waking Up Sysadmin
Fifteen concurrency, async, and waiting guides: threads and synchronization, coroutines, and wake latency, each with a one-line summary and a link to the full guide.
-
Hex-Dumping a 64 MiB Binary, Measured: xxd vs hexdump vs od Sysadmin
Hex-dumping the same 64 MiB binary takes 0.68 seconds with xxd -p and 6.57 with hexdump -C — and default od and hexdump collapse 4,194,304 lines of zeros into 3, while bare hexdump prints byte-swapped word pairs.
-
How Fast Does systemd Restart a Crashed Service? Restart=always vs on-failure, Measured — and the Crash Loop It Refuses Sysadmin
With RestartSec at its 100ms default, systemd takes 0.252 seconds to restart a crashing service, not 0.100 — the delay is a minimum, and systemd adds about 0.15 seconds of its own. on-failure restarts a crashing service exactly like always, and the default start limit stops the loop after 5 restarts.
-
What Does std::generator Cost, Measured? C++
Summing 10 million values costs 0.024 seconds through std::generator and 0.014 through a plain loop on GCC 14 — 1.6 to 1.8 times — while a views::iota pipeline ties the loop at zero allocations, and a second pass over a consumed generator is undefined behavior that segfaults on this libstdc++.
-
Cutting a Million-Line File Into Ten, Measured: split vs csplit vs awk Sysadmin
Splitting a million-line file into ten chunks takes 0.031 seconds with split and 0.31 with awk — and split -n r/10 scrambles the order, split -b makes an eleventh chunk, and csplit leaves an empty first file when the pattern matches line 1.
-
Copying a Sparse File, Measured: Which Tools Preserve the Holes Sysadmin
Copying a 1 GiB sparse file takes 0.004 seconds with plain cp and 1.7 seconds with plain rsync — and cp keeps the file at 3 MiB on disk while rsync expands it to the full 1 GiB. dd conv=sparse and rsync --sparse preserve the holes at a cost; cat and plain dd fill them.
-
Seeing the Hidden Characters, Measured: cat -A vs sed -n l vs od -c Sysadmin
Seeing the hidden characters in a million-line file takes 0.055 seconds with cat -A and 5.7 with od -c — but cat -v leaves every tab literal, sed -n l folds long lines so a million-line file prints 1,001,020 lines, and default od silently drops 97 lines to star elision.
-
Numbering a Million Lines, Measured: cat -n vs nl vs awk vs grep -n Sysadmin
Numbering a million lines takes 0.077 seconds with cat -n and 0.21 with nl — but nl numbers only 950,000 of the 1,000,000 lines by default, a lone backslash-colon line un-numbers the rest of the file, and nl -ba produces output byte-identical to cat -n at 2.8 times the cost.
-
Finding Lines by Prefix: look vs grep vs rg vs awk vs sed, Measured Sysadmin
Finding 1,000 lines by prefix in a million-line sorted file costs 0.0013 seconds with look, 0.0051 with rg and 0.0088 with grep on util-linux 2.39.3 — but look returns nothing at all on unsorted input, and its -b flag does not exist on Linux.
-
Joining Two Files on a Key: join vs awk, Measured Sysadmin
Merging a million fact rows against a 100,000-key lookup costs 0.07 seconds with join on pre-sorted inputs and 0.46 with an awk hash merge on GNU coreutils 9.4 and gawk 5.2.1 — and even paying for both sorts, join still wins 1.73 times over awk.
-
Wrapping Long Lines, Measured: fold vs fmt vs awk Sysadmin
Wrapping 510,000 lines to 80 columns costs 0.23 seconds with fold and 0.72 with fmt on GNU coreutils 9.4 — fmt is 3.15 times slower and silently joins short lines, while fold cuts a 200-character word in half and fmt refuses to break it at all.
-
Tabs to Spaces and Back, Measured: expand vs unexpand vs sed vs awk vs perl Sysadmin
Converting a million tabbed lines to spaces takes 0.11 seconds with expand and 0.53 with awk — but a naive sed substitution is byte-identical to expand when every tab sits on a tab stop and misaligns 266,335 lines otherwise, and unexpand -t 8 silently converts mid-line blanks exactly like -a.
-
Editing a File In Place, Measured: sed -i vs perl -pi vs awk Sysadmin
Editing a million-line log in place costs 0.18 seconds with sed -i and 0.23 with perl -pi on GNU sed 4.9 and Perl 5.38 — the backup costs nothing, the awk temp-file form costs twice as much, and every one of the six forms replaces the file instead of editing it, breaking symlinks and hard links.
-
How Fast Do std::latch and std::barrier Wake Threads? Measured — 9 to 68 Times Faster Than a Condition Variable C++
On the same Linux box, std::latch wakes a waiting thread in 364 nanoseconds where a mutex and condition_variable take 4,342 — 11.9 times slower at 2 threads, 68.1 times at 8. std::barrier beats a hand-rolled condition-variable barrier by 1.4 to 1.8 times per phase. The published latency tables assert both numbers without measuring either.
-
Copying a Directory Tree, Measured: cp -a vs rsync -a vs tar-pipe Sysadmin
Copying a 10,000-file tree takes 0.16 seconds with a tar pipe and 0.38 with rsync -a — but on a single 1 GiB file cp -a wins at 0.45 seconds, rsync -a without a trailing slash nests the whole tree one level down, and tar keeps the seconds but not the nanoseconds.
-
Converting CRLF to LF, Measured: tr vs sed vs perl vs awk Sysadmin
Converting a million CRLF lines to LF takes 0.12 seconds with tr and 0.48 with awk — but tr deletes 1,000 carriage returns the other three preserve, sed, perl and awk produce byte-identical output, and awk adds a newline the file never had.
-
Copying a File Without read() and write() Is About Twice as Fast: sendfile vs copy_file_range vs splice, Measured Sysadmin
At 1 GiB, sendfile, copy_file_range, and splice copy a file in 365–467 ms against 854 ms for a read/write loop on median — about twice as fast. At 64 MiB the edge is gone, and at 1 MiB it is noise.
-
Waking a Thread: pipe vs eventfd vs signalfd, Measured Sysadmin
Pipe, eventfd, and signalfd all wake a blocked thread in ~0.04 ms. The difference is 1,000 events: pipe keeps all 1,000, eventfd counts them, signalfd keeps one.
-
paste vs join, Measured: Fast by Position, Wrong by Key Sysadmin
On a million lines, paste merges two files in 0.087 seconds and join takes 0.155 — but paste pairs rows by position, not by key. On shuffled files every one of the million pairings is wrong, and on a file with 1,000 missing keys 997,204 rows carry the wrong value. join drops unmatched keys and fails loudly on unsorted input.
-
mv Across Filesystems, Measured: One Rename or a Full Copy Sysadmin
Moving a 1 GiB file with mv takes 0.002 seconds on one filesystem and about 1 second across filesystems. A 10,000-file tree is the same story: one rename on the same filesystem, a full copy across. mv preserves the timestamp across filesystems; plain cp does not.
-
Pulling One Field Out of a Million JSON Lines: jq vs Python vs grep, Measured Sysadmin
grep pulls one field from a million JSON lines 4.3x faster than jq and 5.1x faster than Python — until a nested key with the same name adds 1,000 extra lines.
-
inotify vs Polling: Measured Wake Latency, Queue Overflow, and the Non-Recursive Trap Sysadmin
A blocked inotify read wakes in about 0.087 milliseconds. A 10 millisecond stat poller takes about 6.1 milliseconds on median, and a 100 millisecond poller about 40.9 milliseconds. The queue holds exactly 16,384 events before it overflows, and a directory watch never sees a grandchild change.
-
grep -F vs -E vs -P, Measured: Same Pattern, Three Engines, One Silent Trap Sysadmin
On a million log lines, grep -F and grep -E tie at 0.040 seconds on a plain literal while grep -P costs 0.099 — 2.5 times more for the same 49,533 lines. LC_ALL=C halves -P and barely moves -E. And on a dotted service name, -E and -P silently return 10,058 lines -F does not.