<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Design-Patterns on Pavel Guzenfeld</title><link>https://pavelguzenfeld.com/tags/design-patterns/</link><description>Recent content in Design-Patterns on Pavel Guzenfeld</description><image><title>Pavel Guzenfeld</title><url>https://pavelguzenfeld.com/images/og-default.png</url><link>https://pavelguzenfeld.com/images/og-default.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 23 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://pavelguzenfeld.com/tags/design-patterns/index.xml" rel="self" type="application/rss+xml"/><item><title>C++ State Machine, Three Ways: Switch/Case, GoF unique_ptr, and C++23 Variant — Benchmarked</title><link>https://pavelguzenfeld.com/posts/cpp-state-pattern-switch-oop-variant-benchmarked/</link><pubDate>Sat, 23 May 2026 00:00:00 +0000</pubDate><guid>https://pavelguzenfeld.com/posts/cpp-state-pattern-switch-oop-variant-benchmarked/</guid><description>Three implementations of the same aircraft lifecycle FSM — a switch/case flat machine, the classic GoF State pattern with unique_ptr, and a C++23 compile-time variant/visit design — compiled with GCC 14 at -O2 -std=c++23, measured with nanobench, and linked to four live Godbolt sessions. The headline numbers: for a full seven-event mission cycle, the variant approach is 6× faster than OOP and switch/case is essentially free (the optimizer evaluates the constant-input trace at compile time). On the steady-state telemetry hot path, switch runs at 0.56 ns/event, variant at 1.07 ns/event, OOP at 1.20 ns/event. The culprit is not virtual dispatch — it is heap allocation. A follow-up section adds get_if chains and the [[likely]] attribute: on single-variant dispatch all four strategies land within 0.11 ns.</description></item></channel></rss>