Checking your account

You can read the lesson while its saved answers and constructions load. Learning controls will open once that work is ready.

Python Testing and Project Tools

Find where the report spends its time

Coding challenges

BOTIE

Multiply calls by self_ms_per_call for each row, find the largest total, and return that complete profile row. For the first example, reading costs 200 ms, formatting 100 ms and validation 8 ms. If totals tie, keep the first tied row.
Ready to test
0 passed · 0 failed · 2 not run

An empty floor. Start with the information your machine needs.

Received result

Your answer will arrive here.

Examples, experiments and workspace controls
Live values

Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.

Try your own inputs

Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.

Start at an output arrow, then click or drag to an input. Drag empty space to pan. Delete removes a selection. Ctrl/Cmd+Z undoes a change.
Context for this challenge

Multiply calls by self_ms_per_call for each row, find the largest total, and return that complete profile row. For the first example, reading costs 200 ms, formatting 100 ms and validation 8 ms. If totals tie, keep the first tied row.

The first suspect is the function with the most calls, but call count alone does not show total cost.

Read the calls and self_ms_per_call columns. Multiply them to obtain total self milliseconds. Find the largest cost position, then retrieve that row from the original profile.

Examples and results
Recorded report operations and their costs
  1. operation
    Read source
    calls
    40
    self_ms_per_call
    5
  2. operation
    Format report
    calls
    1000
    self_ms_per_call
    0.1
  3. operation
    Validate records
    calls
    40
    self_ms_per_call
    0.2
Required result
operation
Read source
calls
40
self_ms_per_call
5
Recorded report operations and their costs
  1. operation
    Read source
    calls
    4
    self_ms_per_call
    5
  2. operation
    Format report
    calls
    200
    self_ms_per_call
    0.1
Required result
operation
Read source
calls
4
self_ms_per_call
5
Try a fresh construction

This clears this draft, including its undo history. Earlier successful attempts stay recorded. Build again without opening hints to record an independent attempt.

Stuck? Inspect a worked construction

The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.

Assumptions and test precision

These measurements are invented and supplied. The blocks calculate estimates from them; they do not time Python. A real optimization also needs fresh measurements and unchanged behavior tests. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

Few expensive calls outweigh many quick ones

This check uses the pieces from “Calculate the cost of each operation”.

BOTIE

Formatting runs 1000 times at 0.01 ms per call. Reading runs twice at 40 ms per call. Compare the total self time before choosing the larger-cost operation.
Recorded report operations and their costs
  1. operation
    Format report
    calls
    1000
    self_ms_per_call
    0.01
  2. operation
    Read source
    calls
    2
    self_ms_per_call
    40

Saving your prediction runs your current construction on these inputs and checks the earlier examples too.

Build a construction in the workspace above first. This case will test those pieces.

Which measurement would show that a proposed repair helped the workload you care about?

Measure the changed program again before choosing the next optimization.

These measurements are invented and supplied. The blocks calculate estimates from them; they do not time Python. A real optimization also needs fresh measurements and unchanged behavior tests.

← Logging and Debugging