Skip to content

t-flora/cpp-perf-foundations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ for High-Performance Engineering: 6-Day Foundational Project Series

A progressive series of one-day C++ projects designed to build the foundational skills needed for high-performance systems development. Each project introduces essential concepts while building toward the competence required for high-performance engineering. Some of these projects may take longer than a day, and that's fine!

Complete Solutions: This is the main branch containing project implementations.

For learners: Clone the template branch to get started:

git clone -b template https://github.com/t-flora/cpp-perf-foundations.git

For instructors/reference: You're in the right place! This branch contains implementations.

Branch Structure

This repository uses a two-branch approach:

  • template branch: Empty project templates with starter code and TODO comments for learners
  • main branch: Complete implementations and solutions for reference

Workflow for learners:

# Clone template branch to start learning
git clone -b template https://github.com/t-flora/cpp-perf-foundations.git
cd cpp-perf-foundations

# Work on your solutions...

# Optional: Compare with complete solutions  
git remote add upstream https://github.com/t-flora/cpp-perf-foundations.git
git fetch upstream main
git checkout -b solutions upstream/main

Repository Structure

cpp-foundations/
├── README.md                 # This file
├── CMakeLists.txt           # Root CMake file
├── .github/
│   └── workflows/
│       └── ci.yml           # GitHub Actions CI
├── day1-cmake-ci/
│   ├── README.md
│   ├── CMakeLists.txt
│   ├── src/
│   │   ├── calculator.h
│   │   ├── calculator.cpp
│   │   └── main.cpp
│   └── tests/
│       └── test_calculator.cpp
├── day2-header-library/
│   ├── README.md
│   ├── CMakeLists.txt
│   ├── include/
│   │   └── vector_math/
│   │       └── vector_math.h
│   ├── examples/
│   │   └── example_usage.cpp
│   └── tests/
│       └── test_vector_math.cpp
├── day3-docker-benchmarks/
│   ├── README.md
│   ├── CMakeLists.txt
│   ├── Dockerfile
│   ├── run_benchmarks.sh
│   ├── src/
│   │   └── sorting_benchmarks.cpp
│   └── results/
│       └── .gitkeep
├── day4-container-performance/
│   ├── README.md
│   ├── CMakeLists.txt
│   ├── src/
│   │   └── container_comparison.cpp
│   ├── scripts/
│   │   └── plot_results.py
│   └── results/
│       └── .gitkeep
├── day5-realtime-processor/
│   ├── README.md
│   ├── CMakeLists.txt
│   ├── src/
│   │   └── market_data_processor.cpp
│   ├── data/
│   │   └── sample_trades.csv
│   └── tests/
│       └── test_vwap.cpp
└── day6-concurrent-calculator/
    ├── README.md
    ├── CMakeLists.txt
    ├── src/
    │   ├── thread_pool.h
    │   ├── concurrent_calculator.cpp
    │   └── benchmark_concurrency.cpp
    ├── tests/
    │   └── test_thread_safety.cpp
    └── scripts/
        └── plot_scaling.py

Project Overview

Day 1: CMake + CI Hello World

Goal: Master the build system that every C++ project uses

What You'll Build: Simple calculator library with multiple source files

  • calculator.h/cpp with add/subtract/multiply/divide functions
  • main.cpp that demonstrates library usage
  • CMake configuration for library and executable
  • GitHub Actions CI pipeline for Linux/macOS
  • clang-format integration for code style

Skills Gained:

  • CMake basics (targets, linking, dependencies)
  • CI/CD setup with GitHub Actions
  • Professional C++ project structure
  • Code formatting and style consistency

Essential Reading (2-3 hours before coding):

Why it matters: Every real C++ project needs this foundation. Without solid build systems, you can't collaborate or deploy code professionally in any high-performance domain.


Day 2: Header-Only Math Library

Goal: Understand how modern C++ libraries are distributed

What You'll Build: Vector/matrix operations library for 2D/3D vectors

  • Single header file with templated vector operations
  • Example usage demonstrating the API
  • CMake export files for easy integration

If time permits:

  • Documentation with usage examples
  • A few unit tests with Google Test

Skills Gained:

  • Template programming fundamentals
  • Header-only library design patterns
  • Package management and distribution
  • API design principles

Essential Reading (2-3 hours before coding):

Additional resources:

Tools to for quick performance scans:

Why it matters: Most high-performance C++ libraries are header-only for optimal compilation and inlining. Understanding this pattern is essential for systems programming.


Day 3: Containerized Benchmark Runner

Goal: Learn Docker + performance measurement

What You'll Build: Benchmark suite comparing sorting algorithms

  • Performance comparison of std::sort vs quicksort vs radix sort
  • Google Benchmark integration with proper statistical analysis
  • Multi-stage Dockerfile (separate build and runtime stages)
  • Automated script to run containers and export results
  • Performance graphs and analysis

Skills Gained:

  • Docker containerization for C++ projects
  • Scientific performance measurement
  • Benchmark design and interpretation
  • CI integration with performance testing

Essential Reading (2-3 hours before coding):

Why it matters: All modern high-performance systems run in containers, and performance measurement is critical for optimization decisions.


Day 4: Data Structure Performance Explorer

Goal: Understand when to use different containers

What You'll Build: Systematic performance comparison of STL containers

  • Compare std::vector, std::unordered_map, std::map, std::set for different operations
  • Vary data sizes (100, 10K, 1M elements) and access patterns
  • Generate CSV results with timing data
  • Python script to create performance visualizations
  • Decision guide for container selection

Skills Gained:

  • Deep understanding of STL container performance characteristics
  • Systematic benchmarking methodology
  • Data analysis and visualization
  • Performance-driven decision making

Essential Reading (2-3 hours before coding):

Why it matters: High-performance systems live or die on container choice. A wrong data structure can cost microseconds per operation, which translates to real performance bottlenecks.


Day 5: Real-Time Data Processor

Goal: Handle streaming data efficiently

What You'll Build: Mock data processor with real-time analytics

  • Parse CSV stream of data records (timestamp, identifier, value, quantity)
  • Calculate moving averages and other windowed statistics per identifier
  • Implement sliding window calculations using ring buffers
  • Output real-time results with configurable update frequency
  • Handle data validation and error cases

Skills Gained:

  • Stream processing patterns
  • Circular buffers and windowed calculations
  • Real-time analytics concepts
  • Real-time system design principles

Essential Reading (2-3 hours before coding):

Day 6: Concurrent Task Processor

Goal: Learn thread safety and parallel processing fundamentals

What You'll Build: Multi-threaded mathematical computation system

  • Thread pool for distributing CPU-intensive calculations
  • Thread-safe queue using std::mutex and std::condition_variable
  • Parallel processing of mathematical operations (matrix multiplication, prime finding)
  • Benchmark comparing single-threaded vs multi-threaded performance
  • Proper synchronization and resource management

Skills Gained:

  • std::thread, std::mutex, std::condition_variable
  • Thread pool design patterns
  • Race condition prevention
  • Lock-free data structures (std::atomic basics)
  • Scalability measurement and analysis

Essential Reading (2-3 hours before coding):

Why it matters: High-performance systems are inherently concurrent - data processing, task scheduling, and resource management all happen in parallel. Understanding thread safety is essential for scalable systems.


Prerequisites

  • C++17 or later compiler (GCC 9+, Clang 10+, or MSVC 2019+)
  • CMake 3.16+
  • Git
  • Docker (for Day 3)
  • Python 3.8+ with matplotlib (for Day 4 visualization)

Building All Projects

git clone <your-repo-url>
cd cpp-foundations
mkdir build && cd build
cmake ..
make -j$(nproc)
ctest  # Run all tests

Building Individual Projects

cd day1-cmake-ci
mkdir build && cd build
cmake ..
make
./calculator_demo

Learning Progression

Each day builds on the previous:

  1. Build Systems → You can compile and distribute C++ code professionally
  2. Header Libraries → You understand modern C++ distribution patterns
  3. Containers + Benchmarks → You can measure and optimize performance
  4. Data Structures → You make informed choices about algorithms and containers
  5. Stream Processing → You can handle real-time data efficiently
  6. Concurrency → You understand thread safety and parallel processing fundamentals

Success Criteria

After completing all 6 projects, you should be able to:

  • Set up a new C++ project with CMake and CI from scratch
  • Design and implement header-only libraries
  • Write and interpret performance benchmarks
  • Choose appropriate data structures for different use cases
  • Process streaming data efficiently
  • Write thread-safe concurrent code
  • Containerize C++ applications for deployment

Next Steps

With these foundational skills mastered, you'll be ready to tackle more ambitious projects like:

  • High-performance order book implementation
  • Low-latency data processing systems
  • Distributed system components
  • Real-time analytics engines

Daily Study Schedule

Each day should follow this pattern:

  1. Morning (2-3 hours): Read assigned materials for the day
  2. Afternoon (4-5 hours): Implement the project
  3. Evening (1 hour): Document learnings and prepare for next day

Time Management: Don't spend more than 3 hours on reading per day. The goal is practical competence, not theoretical mastery.

Versioning and Releases

This project follows semantic versioning adapted for educational content:

  • Major: Breaking changes to project structure or prerequisites
  • Minor: New projects or significant enhancements
  • Patch: Bug fixes and documentation updates

Contributing

This is a learning repository. Each project should be:

  • Completable in one focused day (6-8 hours)
  • Well-documented with clear learning objectives
  • Professionally structured with proper testing
  • Incrementally building toward real-world skills

Remember: The goal isn't to build the most sophisticated systems possible, but to develop the foundational competence that makes sophisticated systems achievable in the first place.

About

A 6-day curriculum for building fundamental skills for performance engineering with C++ systems.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors