C++ · Advanced level

Advanced level · Module 4 of 6 · 22 guided hours

Testing and Performance in C++

Write unit tests with a test framework, measure performance with profilers and benchmarks, and optimise based on evidence.

Learning objectives

  • Write unit tests with a C++ test framework
  • Measure performance with profilers and benchmarks
  • Optimise using algorithms and data layout, verifying each change

Topics

  • GoogleTest or Catch2
  • test organisation in CMake
  • algorithmic complexity
  • profiling with perf / Visual Studio profiler
  • benchmarking pitfalls
  • cache-friendly data layout

Lessons

  1. Lesson 1 Unit Testing with a C++ Framework

    Write and run unit tests with GoogleTest or Catch2 integrated into a CMake project.

    test caseEXPECT/REQUIRE assertionsfixturesctest

  2. Lesson 2 Measuring Performance

    Measure before optimising: profile to find hot spots and benchmark changes reliably.

    profilerhot spotbenchmarkrelease build

  3. Lesson 3 Algorithms and Complexity in Practice

    Use algorithmic complexity to make the biggest performance wins: better algorithms and data structures.

    Big-O notationO(n²) vs O(n log n)hash lookupreserve()

  4. Lesson 4 Memory Layout and Cache-Friendly Code

    Understand why contiguous data is fast, and lay out data so the processor's caches work for you.

    CPU cachecontiguous memorypointer chasingstructure of arrays

Practical activity

Profile the sensor processor on a large data set, find the hottest function, optimise it and prove the speed-up with repeatable measurements while tests stay green.

Expected outcomes

  • Automated tests for C++ libraries
  • Optimisations backed by measurements

Assessment

Practical: submit tests and a before/after benchmark report for one optimisation; marked on correctness and measurement quality.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.