C++ Performance Quiz
How well do you know what the compiler does? Pick a question and find out.
No progress yet. Start the first question when you're ready.
-
1. Memory Layout: Array of Structs vs Struct of Arrays
2 snippets ✓ Completed -
2. Atomic Bit Set: Need Return Value or Not
2 snippets ✓ Completed -
3. Atomic Increment Ordering: relaxed vs. seq_cst
2 snippets ✓ Completed -
4. Atomic Store Ordering: memory_order_release vs memory_order_seq_cst
2 snippets ✓ Completed -
5. Lambda Capture: Value Capture vs Reference Capture
2 snippets ✓ Completed -
6. Atomic Counter Updates: Per-Operation vs Batched Flush
2 snippets ✓ Completed -
7. Sorted Array Search: std::lower_bound vs. Linear Scan
2 snippets ✓ Completed -
8. Packed Bit Storage: Bit Fields vs Manual Bit Masking
2 snippets ✓ Completed -
9. Power-of-Two Indexing: Bitwise AND vs operator%
2 snippets ✓ Completed -
10. Bit Counting: Manual Loop vs std::popcount
2 snippets ✓ Completed -
11. Hash Map Lookup: Bloom Filter Precheck vs Direct Lookup
2 snippets ✓ Completed -
12. Boolean Short-Circuit: Cheap-Then-Expensive vs Expensive-Then-Cheap
2 snippets ✓ Completed -
13. Conditional Write: Two Control-Flow Styles
2 snippets ✓ Completed -
14. Aliasing Model: char* vs char8_t* Stores
2 snippets ✓ Completed -
15. Lookup Table: Static Array vs. Stack Array
2 snippets ✓ Completed -
16. Dense Integer Keys: Counting Sort vs std::sort
2 snippets ✓ Completed -
17. Membership Checks: Dense Bitset vs Sparse Hash Set
2 snippets ✓ Completed -
18. Integer Division: Compile-Time Constant vs. Runtime Variable
2 snippets ✓ Completed -
19. Type Check in Hot Loop: dynamic_cast vs Explicit Tag
2 snippets ✓ Completed -
20. std::vector Insertion: emplace_back vs push_back
2 snippets ✓ Completed -
21. Removing Elements from a Vector: Two Approaches
2 snippets ✓ Completed -
22. Error Handling Under Frequent Failures: Exception vs Error Code
2 snippets ✓ Completed -
23. Cache Coherency: Packed vs Padded Thread Counters
2 snippets ✓ Completed -
24. Free Function vs. Member Function
2 snippets ✓ Completed -
25. Float Parsing: std::from_chars vs strtod
2 snippets ✓ Completed -
26. API Shape: hasFailure vs hasValue
2 snippets ✓ Completed -
27. Read-Heavy Map Lookup: unordered_map vs. Sorted Vector + Binary Search
2 snippets ✓ Completed -
28. Map String Lookup: Two Key-Passing Styles
2 snippets ✓ Completed -
29. Struct Layout: Combined vs Split Field Storage
2 snippets ✓ Completed -
30. Bounded Buffer: inplace_vector vs std::vector
2 snippets ✓ Completed -
31. Division by Constant: Integer vs Float Path
2 snippets ✓ Completed -
32. Lambda Closure Performance in a Tight Loop
2 snippets ✓ Completed -
33. Branch Annotation Direction: [[likely]] vs [[unlikely]]
2 snippets ✓ Completed -
34. Searching Sorted Data: Linear Search vs Binary Search
2 snippets ✓ Completed -
35. Container Iteration: std::list vs std::vector
2 snippets ✓ Completed -
36. std::list Traversal: Forward vs Two-Ended
2 snippets ✓ Completed -
37. Access Pattern: Function-local static vs Global
2 snippets ✓ Completed -
38. Character Lower-casing: Locale-aware vs Lookup Table
2 snippets ✓ Completed -
39. Loop-Carried Dependency: Single vs Split Accumulator
2 snippets ✓ Completed -
40. Shared Pointer Creation: new vs make_shared
2 snippets ✓ Completed -
41. Unique Pointer Array Init: Default vs Value Initialisation
2 snippets ✓ Completed -
42. Map Lookup: find() vs. count() + at()
2 snippets ✓ Completed -
43. Sorted Map Insertion: Hint vs No Hint
2 snippets ✓ Completed -
44. Key Lookup: std::map vs std::unordered_map
2 snippets ✓ Completed -
45. 2D Array Traversal: Row-Major vs Column-Major
2 snippets ✓ Completed -
46. Memory Allocation: Object Pool vs Repeated new/delete
2 snippets ✓ Completed -
47. Return Paths and NRVO: Single Local vs Multiple Locals
2 snippets ✓ Completed -
48. Thread-Safe Counter: Two Synchronization Approaches
2 snippets ✓ Completed -
49. std::vector Reallocation: noexcept Move Constructor
2 snippets ✓ Completed -
50. Returning a Named Local: Plain Return vs std::move Return
2 snippets ✓ Completed -
51. Median Selection: nth_element vs Full Sort
2 snippets ✓ Completed -
52. One-Time Initialization: std::call_once vs Function-Local static
2 snippets ✓ Completed -
53. Returning std::optional<Result>: Wrapper Local vs Value Local
2 snippets ✓ Completed -
54. Top-K Selection: partial_sort vs Full Sort
2 snippets ✓ Completed -
55. Single-Threaded Counter: Plain int vs std::atomic
2 snippets ✓ Completed -
56. Top Element Maintenance: Priority Queue vs Sorted Insert
2 snippets ✓ Completed -
57. Range-based for loop: copy vs reference
2 snippets ✓ Completed -
58. std::regex: Function-Local vs. Static-Local Declaration
2 snippets ✓ Completed -
59. std::vector Growth: reserve Before push_back vs Without
2 snippets ✓ Completed -
60. std::vector Pre-allocation: reserve vs resize
2 snippets ✓ Completed -
61. Small-Collection Membership: std::set vs std::unordered_set
2 snippets ✓ Completed -
62. Shared Counter Under Contention: Sharded vs Single Atomic
2 snippets ✓ Completed -
63. Range Loop Over shared_ptr: By-Value vs By-Reference Variable
2 snippets ✓ Completed -
64. Smart Pointer Move: shared_ptr Copy vs. unique_ptr Move
2 snippets ✓ Completed -
65. std::function with Large Objects: Two Capture Strategies
2 snippets ✓ Completed -
66. std::string: Tokenization and Small String Optimization
2 snippets ✓ Completed -
67. std::sort Comparator: Function Pointer vs Lambda
2 snippets ✓ Completed -
68. Branch Prediction: Sorted vs. Shuffled Data
2 snippets ✓ Completed -
69. SSE Multiply: Scalar Lane vs Packed Lanes
2 snippets ✓ Completed -
70. Buffer Allocation: Heap Buffer vs Stack Buffer
2 snippets ✓ Completed -
71. std::any Storage: Small Object vs Heap-backed Large Object
2 snippets ✓ Completed -
72. Buffer Equality: std::equal vs std::memcmp
2 snippets ✓ Completed -
73. Buffer Zero-Initialization: std::fill vs. memset
2 snippets ✓ Completed -
74. Callback Dispatch: std::function vs Template Parameter
2 snippets ✓ Completed -
75. Two-Word Readback Patterns
2 snippets ✓ Completed -
76. Copy vs Move Semantics: std::string Performance
2 snippets ✓ Completed -
77. Integer-to-String Conversion: std::to_string vs std::to_chars
2 snippets ✓ Completed -
78. String Building: Two Concatenation Styles
2 snippets ✓ Completed -
79. String Building: operator+ in Loop vs reserve+append
2 snippets ✓ Completed -
80. Integer Parsing: atoi vs. std::from_chars
2 snippets ✓ Completed -
81. Substring Extraction: Owning String vs String View
2 snippets ✓ Completed -
82. Copying a Short String into a Large Buffer
2 snippets ✓ Completed -
83. Struct Field Ordering and Implicit Padding
2 snippets ✓ Completed -
84. Structured Binding: Copy vs Reference
2 snippets ✓ Completed -
85. Dense Integer Dispatch: switch vs. Function-Pointer Table
2 snippets ✓ Completed -
86. Tail Recursion Optimization
2 snippets ✓ Completed -
87. Integer Formatting: std::to_chars vs snprintf
2 snippets ✓ Completed -
88. Integer-to-String Conversion: std::to_string vs std::format
2 snippets ✓ Completed -
89. Type Check in Loop: typeid vs Explicit Tag
2 snippets ✓ Completed -
90. Uncontended Mutex Guard: Inside vs. Outside the Loop Body
2 snippets ✓ Completed -
91. Hash Lookup Tuning: Two Bucket Density Settings
2 snippets ✓ Completed -
92. Unordered Map Build: No reserve() vs reserve()
2 snippets ✓ Completed -
93. UTF-8 Code Point Counting: Nibble Table vs Range Checks
2 snippets ✓ Completed -
94. Polymorphic Dispatch: Virtual Functions vs std::variant
2 snippets ✓ Completed -
95. Boolean Vector Storage: std::vector<bool> vs std::vector<uint8_t>
2 snippets ✓ Completed -
96. Removing a Vector Element: Stable vs Swap Removal
2 snippets ✓ Completed -
97. Element Storage: Pointer-Owned vs Value-Owned Elements
2 snippets ✓ Completed -
98. Virtual Call Devirtualization: With and Without final
2 snippets ✓ Completed -
99. Polymorphic Dispatch: Virtual Function vs CRTP
2 snippets ✓ Completed -
100. Large Stack Buffer: Initialization
2 snippets ✓ Completed