Section 18.5.12

Energy cannot be inferred from timing alone

Definition

Energy, for an electronic device, is the total electrical work that its supply delivers to it over an interval of time, measured in joules. Power is the rate at which that energy is delivered, measured in watts; 1 watt is 1 joule per second. Energy over an interval is the area under the curve of power against time, so it depends both on the length of the interval and on the power drawn throughout it. A timing measurement gives only the length, so timing alone cannot determine energy.

The idea

A radio exchange, one message sent and its reply received, can be made faster by running the processor at a higher clock frequency or by using more hardware in parallel. Both changes usually raise the power that the device draws while it works. Take two invented designs. Design A completes the exchange in 2 seconds at a constant 1 watt; design B completes it in 1 second at 3 watts. A latency plot shows B twice as fast. Yet A uses 1×2=21 \times 2 = 2 joules and B uses 3×1=33 \times 1 = 3 joules, so the faster design uses 1.5 times as much energy.

The reverse also happens. A faster design that draws only a little more power finishes sooner, lets the device return earlier to a sleep state in which it draws almost nothing, and can use less energy. Timing alone therefore does not even tell which of two designs uses less energy.

The picture to keep is an area. Plot power against time; the energy is the area under the curve. A timing measurement gives the width of that area. Its height comes only from a power measurement, and the height is rarely constant: a radio draws short bursts of high power to transmit and to receive, separated by long stretches of low power. The picture also shows why the window, the interval from a stated start event to a stated end event, must be named. A window that ends when the reply arrives leaves out the time the device then spends listening for further messages and going back to sleep, and that tail can hold much of the energy.

How it works

Measuring the energy of an operation takes six steps.

  1. State the quantity. Name what is measured, such as the energy per completed exchange, and fix the window by its start event and its end event. Decide whether start-up, waiting, retransmissions §7.36 (messages sent again after a loss) and the return to sleep belong inside the window.

  2. Choose the measurement point. A measurement at the supply input of the circuit board gives the energy of the whole board, including its voltage regulators (circuits that hold a supply voltage steady), indicator lights and sensors. A claim about one chip needs a measurement at that chip’s own supply connection.

  3. Record current and voltage. The power at each instant is the voltage times the current. A common method passes the supply current through a shunt, a small resistor of known resistance, and measures the small voltage across it; the current is that voltage divided by the resistance. The supply voltage is recorded at the same instants, or held constant by a regulated supply and recorded.

  4. Sample fast enough. A radio burst can last less than a millisecond. A meter that takes one reading every 10 milliseconds can miss such a burst entirely, so the interval between samples must be short compared with the shortest burst.

  5. Mark the window in the same record. The device signals its start and end events, for example by switching an output pin that the measuring instrument records alongside the power samples, so that the events and the samples share one clock.

  6. Add up and divide. Sum power times sample interval over the samples inside the window, then divide by the number of operations completed in the window.

When two designs are compared, everything except the design must stay the same; the answer at the end of this entry lists what to hold fixed. Attached equipment is easy to overlook. A debug probe, a device that connects a computer to a chip for debugging, can keep parts of a chip powered and raise the measured sleep power, and a logging connection that runs during the window adds power of its own, a form of instrumentation overhead §11.32.

Worked example

Two invented designs perform the same exchange on a device supplied at 3 volts. Design A is active for 4 milliseconds and draws 5 milliamperes. Design B is active for 2 milliseconds and draws 12 milliamperes. After the exchange, both keep the receiver on for 5 milliseconds at 6 milliamperes to catch a possible reply, and then sleep. Power is voltage times current. While active, A draws 3×0.005=0.0153 \times 0.005 = 0.015 watt, which is 15 milliwatts, and B draws 3×0.012=0.0363 \times 0.012 = 0.036 watt, which is 36 milliwatts. While listening, either design draws 3×0.006=0.0183 \times 0.006 = 0.018 watt, which is 18 milliwatts.

One milliwatt for one millisecond is 10−3×10−3=10−610^{-3} \times 10^{-3} = 10^{-6} joule, one microjoule. The active energy of A is 15×4=6015 \times 4 = 60 microjoules, and that of B is 36×2=7236 \times 2 = 72 microjoules. B is twice as fast and uses 72/60=1.272 / 60 = 1.2 times the energy.

The listening tail costs 18×5=9018 \times 5 = 90 microjoules for either design. Over the whole window, A uses 60+90=15060 + 90 = 150 microjoules and B uses 72+90=16272 + 90 = 162 microjoules, a ratio of 162/150=1.08162 / 150 = 1.08. A window that ends with the active part reports that B costs 20% more; a window that includes the tail reports 8% more. Both numbers are correct answers to different questions, so a report must state its window.

Failures change the result again. Suppose that one in every 10 exchanges by B fails once and is then repeated successfully, that A never fails, and that a failed attempt costs as much as a successful one. Ten completed exchanges by B then take 11 attempts, so B’s energy per completed exchange is 11×162/10=178.211 \times 162 / 10 = 178.2 microjoules, which is 178.2/150=1.188178.2 / 150 = 1.188 times that of A.

Stated precisely

Let V(t)V(t) be the voltage in volts and I(t)I(t) the current in amperes at one measurement point at time tt, in seconds. The power through that point is P(t)=V(t)I(t)P(t) = V(t)\,I(t) watts. The energy delivered through that point in the window from time t0t_0 to time t1t_1 is E=∫t0t1P(t)dtjoules,E = \int_{t_0}^{t_1} P(t)\,dt \ \text{joules}, the area under the power curve. When the power is constant, E=P(t1−t0)E = P\,(t_1 - t_0). From samples P1,…,PmP_1, \dots, P_m of the power taken every Δt\Delta t seconds inside the window, the estimate is Ê=∑k=1mPkΔt\hat{E} = \sum_{k=1}^{m} P_k\,\Delta t, where the hat marks an estimate. If nn operations complete in the window, the energy per completed operation is E/nE / n, with the energy of failed attempts counted in EE and the failed attempts not counted in nn. The average power E/(t1−t0)E / (t_1 - t_0) is a finite-window rate §11.41: it describes that window only.

Compare two designs that each run at constant power, with powers PAP_A and PBP_B and durations tAt_A and tBt_B. Design B uses less energy exactly when PBtB<PAtAP_B\,t_B < P_A\,t_A, that is, when PB/PA<tA/tBP_B / P_A < t_A / t_B. A design twice as fast uses less energy only if it draws less than twice the power. A timing result supplies tA/tBt_A / t_B and says nothing about PB/PAP_B / P_A.

The estimate Ê\hat{E} equals the energy of the stated quantity only if four conditions hold.

  1. The right point. Voltage and current are measured at the same point, and that point matches the claim: the board supply for a claim about the board, the chip supply for a claim about the chip.

  2. One clock. Voltage and current are sampled at the same instants, and the start and end events of the window are placed on the same time axis as the samples.

  3. Fast enough sampling. The power changes little within one sample interval, so that no burst falls between samples.

  4. A calibrated instrument with a known effect. The instrument’s error is known from calibration §11.42, and so is its effect on the circuit: a shunt of resistance RR carrying current II lowers the voltage that reaches the device by IRI R.

Limits and common mistakes

Timing gives no energy result, and no battery-life result either. Battery life depends on the average current over the whole cycle of activity and sleep, which long sleep periods often dominate, and on the battery itself: many batteries, coin cells in particular, deliver less of their rated charge at high peak currents and at low temperatures.

Energy at the board supply is not the energy of one chip. Voltage regulators turn part of the energy into heat, and other parts of the board draw their own share.

An average hides bursts. Two power records with the same average can differ in peak current, and a peak can exceed what a small battery can deliver.

Energy per operation must include failed attempts. Dividing the energy of the successful operations alone by their number, after dropping the failed runs, reports less than the device spends. This is a form of survivorship bias §11.30: drawing a conclusion only from the cases that succeeded.

Questions answered

What should an energy experiment control?

An energy experiment should control, and report, everything that changes either the power the device draws or the length of time over which that power is added up, because energy is power accumulated over time. That means:

A timing result controls none of the power side, so it cannot replace this measurement: a design that is twice as fast uses less energy only if it draws less than twice the power.

Related entries: Estimand and estimator (§11.2), Instrumentation overhead (§11.32), Calibration (§11.42), Finite-window rate (§11.41), Survivorship bias (§11.30).