All paths

Fast code: measure, then optimize

Profile real code on an ESP32-C3 with micros() and the cycle counter, then make it fast: Big O, floats, the heap, tables and caches, ending in a starfield fifty times faster.

ESP32-C3-DevKitM-1Free7 lessons6 h4 chapters2,454 XPCoding · Advanced+250 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 6 hours on a simulated ESP32-C3-DevKitM-1. Free, in your browser, every step checked by the simulator.

Chapter 1 project

Big O in practice

Linear search, binary search and a check of every pair, timed at growing sizes: watch time grow like n, like log n and like n squared, and predict the next one.

Open it in the simulator
Chapter 2 project

Memory and allocation

Where globals, the heap and the stack live in the C3's 400 KB, what malloc really costs, why two growing Strings fight over the heap, and how reserve() ends the fight.

Open it in the simulator
Chapter 3 project

Caching

Remember answers instead of working them out again: a memo table takes Fibonacci from 150,049 calls to 47, and a HUD that remembers what it drew stops redrawing every frame.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Measuring

Find where the time goes before changing a line, and how it grows when the data does.

  1. Open227 XP

    Measure first

    One frame of a space game is four jobs. Guess the slow one, then time each with micros(), learn what a measurement can and cannot see, and time a job yourself.

    0 of 5 steps

  2. ProjectLocked500 XP

    Big O in practice

    Linear search, binary search and a check of every pair, timed at growing sizes: watch time grow like n, like log n and like n squared, and predict the next one.

    0 of 5 steps

5 questions, graded as you go.
Chapter 2

The machine

What an instruction, a float and an allocation really cost on a 160 MHz RISC-V core.

  1. Locked250 XP

    Cycle counts

    Read the core's own cycle counter, see what an add, a multiply and a divide cost, find out why float math is slow on a chip with no FPU, and dim 1,000 pixels on a budget.

    0 of 5 steps

  2. ProjectLocked500 XP

    Memory and allocation

    Where globals, the heap and the stack live in the C3's 400 KB, what malloc really costs, why two growing Strings fight over the heap, and how reserve() ends the fight.

    0 of 5 steps

5 questions, graded as you go.
Chapter 3

Doing less work

Work things out once and remember them: lookup tables and caches.

  1. Locked250 XP

    Tables vs math

    A sine wave across the panel two ways: sinf() for every column, or a table worked out once. Time both, measure the table's error in pixels, and pick its size.

    0 of 5 steps

  2. ProjectLocked500 XP

    Caching

    Remember answers instead of working them out again: a memo table takes Fibonacci from 150,049 calls to 47, and a HUD that remembers what it drew stops redrawing every frame.

    0 of 5 steps

5 questions, graded as you go.
Chapter 4

Boss

Profile a slow starfield and make it fifty times faster.

  1. Locked227 XP

    Boss: double a frame rate

    A warp-speed starfield runs at 9 frames a second. Profile it, find the job eating the frame, fix it, and push it past double, then past 300 frames a second.

    0 of 5 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Measuring

  1. Measure firstOne frame of a space game is four jobs. Guess the slow one, then time each with micros(), learn what a measurement can and cannot see, and time a job yourself.
  2. Big O in practiceLinear search, binary search and a check of every pair, timed at growing sizes: watch time grow like n, like log n and like n squared, and predict the next one.
Chapter 2

The machine

  1. Cycle countsRead the core's own cycle counter, see what an add, a multiply and a divide cost, find out why float math is slow on a chip with no FPU, and dim 1,000 pixels on a budget.
  2. Memory and allocationWhere globals, the heap and the stack live in the C3's 400 KB, what malloc really costs, why two growing Strings fight over the heap, and how reserve() ends the fight.
Chapter 3

Doing less work

  1. Tables vs mathA sine wave across the panel two ways: sinf() for every column, or a table worked out once. Time both, measure the table's error in pixels, and pick its size.
  2. CachingRemember answers instead of working them out again: a memo table takes Fibonacci from 150,049 calls to 47, and a HUD that remembers what it drew stops redrawing every frame.
Chapter 4

Boss

  1. Boss: double a frame rateA warp-speed starfield runs at 9 frames a second. Profile it, find the job eating the frame, fix it, and push it past double, then past 300 frames a second.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Fast code: measure, then optimize

Is Fast code: measure, then optimize free?

Yes. All 7 lessons of Fast code: measure, then optimize are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real ESP32-C3-DevKitM-1?

No. Every lesson runs on a simulated ESP32-C3-DevKitM-1 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Fast code: measure, then optimize take?

About 6 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Big O in practice, Memory and allocation and Caching.

Where do I start?

With "Measure first", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.