A deterministic counter can stand in for timing work when teaching how to compare paths.

probe counter A counter records how many loop steps were needed without relying on wall-clock time.
comparable paths The two loops do the same kind of work, so their counts can be compared directly.

Timing Probe

limit
TimingProbe.java
Replay: real traced execution (multi-file project)
public class TimingProbe {
    public static void main(String[] args) {
        int limit = 4;
        int slowSteps = 0;
        int fastSteps = 0;

        for (int i = 0; i < limit; i++) {
            slowSteps++;
        }

        for (int i = 0; i < limit; i += 2) {
            fastSteps++;
        }

        System.out.println("slow=" + slowSteps + " fast=" + fastSteps);
    }
}
public class TimingProbe {
    public static void main(String[] args) {
        int limit = 2;
        int slowSteps = 0;
        int fastSteps = 0;

        for (int i = 0; i < limit; i++) {
            slowSteps++;
        }

        for (int i = 0; i < limit; i += 2) {
            fastSteps++;
        }

        System.out.println("slow=" + slowSteps + " fast=" + fastSteps);
    }
}
public class TimingProbe {
    public static void main(String[] args) {
        int limit = 6;
        int slowSteps = 0;
        int fastSteps = 0;

        for (int i = 0; i < limit; i++) {
            slowSteps++;
        }

        for (int i = 0; i < limit; i += 2) {
            fastSteps++;
        }

        System.out.println("slow=" + slowSteps + " fast=" + fastSteps);
    }
}
  1. limit ← 4, slowSteps ← 0, fastSteps ← 0

    1public class TimingProbe {2    public static void main(String[] args) {3        int limit→ 4 = 4;  //@limit=2, 64        int slowSteps→ 0 = 0;5        int fastSteps→ 0 = 0;
  2. slowSteps ← 1

    pass 1 of 4
    7for (int i0 = 0; i < limit4; i++) {8    slowSteps→ 1++;9}
    All 4 passes — pass 1 is the card above
    passislowStepsfastSteps
    100 1
    211 2
    322 3
    433 40 1
  3. fastSteps ← 1

    pass 1 of 2
    11for (int i0 = 0; i < limit4; i += 2) {12    fastSteps→ 1++;13}
  4. fastSteps ← 2

    pass 2 of 2
    11for (int i2 = 0; i < limit4; i += 2) {12    fastSteps→ 2++;13}
  5. System.out.println("slow=" + slowSteps + " fast=" + fastSteps);

    15    System.out.println("slow=" + slowSteps4 + " fast=" + fastSteps2);16}
    outputslow=4 fast=2
  1. limit ← 2, slowSteps ← 0, fastSteps ← 0

    1public class TimingProbe {2    public static void main(String[] args) {3        int limit→ 2 = 2;4        int slowSteps→ 0 = 0;5        int fastSteps→ 0 = 0;
  2. slowSteps ← 1

    pass 1 of 2
    7for (int i0 = 0; i < limit2; i++) {8    slowSteps→ 1++;9}
  3. slowSteps ← 2

    pass 2 of 2
    7for (int i1 = 0; i < limit2; i++) {8    slowSteps→ 2++;9}
  4. fastSteps ← 1

    11for (int i0 = 0; i < limit2; i += 2) {12    fastSteps→ 1++;13}
  5. System.out.println("slow=" + slowSteps + " fast=" + fastSteps);

    15    System.out.println("slow=" + slowSteps2 + " fast=" + fastSteps1);16}
    outputslow=2 fast=1
  1. limit ← 6, slowSteps ← 0, fastSteps ← 0

    1public class TimingProbe {2    public static void main(String[] args) {3        int limit→ 6 = 6;4        int slowSteps→ 0 = 0;5        int fastSteps→ 0 = 0;
  2. slowSteps ← 1

    pass 1 of 6
    7for (int i0 = 0; i < limit6; i++) {8    slowSteps→ 1++;9}
    All 6 passes — pass 1 is the card above
    passislowSteps
    100 1
    211 2
    322 3
    433 4
    544 5
    655 6
  3. fastSteps ← 1

    pass 1 of 3
    11for (int i0 = 0; i < limit6; i += 2) {12    fastSteps→ 1++;13}
    All 3 passes — pass 1 is the card above
    passifastSteps
    100 1
    221 2
    342 3
  4. System.out.println("slow=" + slowSteps + " fast=" + fastSteps);

    15    System.out.println("slow=" + slowSteps6 + " fast=" + fastSteps3);16}
    outputslow=6 fast=3