C++ Performance Quiz
How well do you know what the compiler does? Pick a question and find out.
-
Memory Layout: Array of Structs vs Struct of Arrays
2 snippets -
Atomic Increment Ordering: relaxed vs. seq_cst
2 snippets -
Atomic Store Ordering: memory_order_release vs memory_order_seq_cst
2 snippets -
Lambda Capture: Value Capture vs Reference Capture
2 snippets -
Sorted Array Search: std::lower_bound vs. Linear Scan
2 snippets -
Power-of-Two Indexing: Bitwise AND vs operator%
2 snippets -
Conditional Write: Two Control-Flow Styles
2 snippets -
Lookup Table: Static Array vs. Stack Array
2 snippets -
Integer Division: Compile-Time Constant vs. Runtime Variable
2 snippets -
std::vector Insertion: emplace_back vs push_back
2 snippets -
Removing Elements from a Vector: Two Approaches
2 snippets -
Cache Coherency: Packed vs Padded Thread Counters
2 snippets -
Free Function vs. Member Function
2 snippets -
Read-Heavy Map Lookup: unordered_map vs. Sorted Vector + Binary Search
2 snippets -
Struct Layout: Combined vs Split Field Storage
2 snippets -
Container Iteration: std::list vs std::vector
2 snippets -
std::list Traversal: Forward vs Two-Ended
2 snippets -
Character Lower-casing: Locale-aware vs Lookup Table
2 snippets -
Loop-Carried Dependency: Single vs Split Accumulator
2 snippets -
Shared Pointer Creation: new vs make_shared
2 snippets -
Map Lookup: find() vs. count() + at()
2 snippets -
Key Lookup: std::map vs std::unordered_map
2 snippets -
2D Array Traversal: Row-Major vs Column-Major
2 snippets -
Thread-Safe Counter: Two Synchronization Approaches
2 snippets -
std::vector Reallocation: noexcept Move Constructor
2 snippets -
Returning a Named Local: Plain Return vs std::move Return
2 snippets -
Returning std::optional<Result>: Wrapper Local vs Value Local
2 snippets -
Range-based for loop: copy vs reference
2 snippets -
std::regex: Function-Local vs. Static-Local Declaration
2 snippets -
std::vector Growth: reserve Before push_back vs Without
2 snippets -
std::vector Pre-allocation: reserve vs resize
2 snippets -
shared_ptr in a Loop: Copy per Iteration vs. Reuse Handle
2 snippets -
Smart Pointer Move: shared_ptr Copy vs. unique_ptr Move
2 snippets -
std::string: Short String Optimisation Buffer
2 snippets -
std::sort Comparator: Function Pointer vs Lambda
2 snippets -
Branch Prediction: Sorted vs. Shuffled Data
2 snippets -
Buffer Allocation: Heap Buffer vs Stack Buffer
2 snippets -
Buffer Zero-Initialization: std::fill vs. memset
2 snippets -
Callback Dispatch: std::function vs Template Parameter
2 snippets -
Copy vs Move Semantics: std::string Performance
2 snippets -
Integer-to-String Conversion: std::to_string vs std::to_chars
2 snippets -
String Building: Two Concatenation Styles
2 snippets -
Substring Extraction: Owning String vs String View
2 snippets -
Copying a Short String into a Large Buffer: strncpy vs memcpy
2 snippets -
Dense Integer Dispatch: switch vs. Function-Pointer Table
2 snippets -
Uncontended Mutex Guard: Inside vs. Outside the Loop Body
2 snippets -
UTF-8 Code Point Counting: Nibble Table vs Range Checks
2 snippets -
Removing a Vector Element: Stable vs Swap Removal
2 snippets -
Element Storage: Pointer-Owned vs Value-Owned Elements
2 snippets -
Polymorphic Dispatch: Virtual Function vs CRTP
2 snippets -
Large Stack Buffer: Zero-Initialized vs Uninitialized
2 snippets