Definition
The geometric mean of positive numbers is the th root of their product. It is the average for quantities that combine by multiplication, such as ratios and growth factors: replacing every number by the geometric mean leaves the product unchanged, just as replacing every number by the arithmetic mean §11.12 (the ordinary average) leaves the sum unchanged. Equivalently, it is the result of averaging the logarithms of the numbers and converting back. For ratios it treats a doubling and a halving as equal and opposite changes.
The idea
A new compiler makes benchmark A run in half the time and benchmark B run in twice the time. Measured as speedup §18.1.13, old time divided by new time, the results are 2 and 0.5. Their arithmetic mean is , a 25% average speedup. Now describe the same data the other way round, as the old compiler’s speedup over the new one: 0.5 and 2, whose arithmetic mean is again 1.25. Each compiler appears 25% faster than the other, which is impossible. The geometric mean of 2 and 0.5 is in both directions: no change on balance.
The reason is that ratios live on a multiplicative scale. Doubling and halving are opposite steps of the same size: in powers of two, 2 is and 0.5 is . The arithmetic mean adds the ratios themselves, and on that scale the step from 1 up to 2 is while the step from 1 down to 0.5 is only , so increases outweigh decreases. The geometric mean averages the exponents, and , to 0, and converts back: .
The geometric mean answers one question: what single factor, applied to every benchmark alike, gives the same combined effect. How much faster a fixed mix of programs runs as a whole is a different question, and it needs the actual times.
How it works
Fix one direction for every ratio, for example old time divided by new time, so that values above 1 mean the new system is faster.
Check that every ratio is positive; logarithms, and with them the geometric mean, exist only for positive numbers.
Multiply the ratios and take the th root. With many ratios, average their logarithms instead and raise the base to that average (with base-2 logarithms, compute 2 to the power of the average); this avoids a product too large or too small for the computer’s number format.
Report the individual ratios alongside the summary, and state the set of benchmarks and any weights.
For uncertainty, compute a confidence interval §11.18 for the mean of the logarithms and convert both ends back; the resulting interval is not symmetric around the geometric mean.
Three properties make the geometric mean the natural summary of normalized results, that is, results expressed as ratios to a reference. Reversing the direction of every ratio turns the geometric mean into its reciprocal. The geometric mean of the ratios equals the geometric mean of the divided by the geometric mean of the ; so when two systems are each compared with a reference machine, their ranking does not depend on which reference machine was chosen. And the geometric mean of the speedups is the single speedup that, applied to every benchmark, gives the same product of speedups. The Standard Performance Evaluation Corporation (SPEC) summarizes its SPEC CPU benchmark results this way: each benchmark’s ratio of a reference machine’s time to the measured time, combined by the geometric mean.
Worked example
Four benchmarks take 10, 10, 40 and 20 seconds on the old system and 5, 20, 10 and 20 seconds on the new one. The speedups, old time divided by new time, are , , and .
Geometric mean. The product is , and its fourth root is . Through logarithms: the base-2 logarithms of the speedups are 1, , 2 and 0; their average is ; and , the same value.
Reversed direction, new time divided by old: 0.5, 2, 0.25 and 1. The geometric mean is , exactly , so it tells the same story. The arithmetic mean is , which as a speedup is , not 1.875. The arithmetic mean contradicts itself.
Total time. Running all four once takes seconds on the old system and seconds on the new one, a speedup of . This answers a different question, and its answer depends on how long each benchmark is. The geometric mean ignores the lengths and gives each benchmark one equal vote.
Choice of reference machine. System X takes 2 and 10 seconds on two benchmarks; system Y takes 4 and 5 seconds. Normalizing divides each time by the reference system’s time on the same benchmark, so lower is faster. Normalized to X, Y’s times are and , with arithmetic mean 1.25 against X’s 1, so X looks faster. Normalized to Y, X’s times are and , with arithmetic mean 1.25 against Y’s 1, so Y looks faster. The geometric mean of the other system’s normalized times is with either reference: a tie, whichever reference is chosen. The total time, seconds for X and seconds for Y, favors Y and answers a different question.
Stated precisely
Let be positive numbers. Their geometric mean is where denotes the product of the terms, is the natural logarithm and is its inverse. Any base of logarithm gives the same result if the same base is used to convert back. With weights that sum to 1, the weighted geometric mean is . For positive numbers and :
Reciprocal. , because .
Ratios. , because .
Bounds. . The inequality of arithmetic and geometric means states , where , with equality only when all are equal. Also , where is the harmonic mean. For 2 and 0.5: , and .
Statistical meaning. If the logarithms of the ratios follow a normal distribution, the symmetric bell-shaped distribution of classical statistics, the geometric mean of a sample estimates the median §11.13 ratio.
These properties need four conditions: every value is positive; every ratio is taken in the same direction; every ratio compares the same quantity, such as running time; and the benchmarks are equally important, or their weights are stated.
Limits and common mistakes
Only positive values are allowed. A failed benchmark has no ratio, and a ratio of 0 makes the product 0. A percent change such as must first become a ratio, ; averaging percent changes directly is a common mistake.
The geometric mean is not total time. For a fixed workload in which each benchmark runs a known number of times, the overall speedup is total old time divided by total new time, the ratio of aggregates §11.40. The geometric mean can disagree with it (1.414 against 1.455 above) and can even point the other way: speedups of 2 on a 1-second benchmark and on a 100-second benchmark have a geometric mean of , yet the total time grows from to seconds.
A summary can hide a regression. Speedups of 10, 10 and 0.01 multiply to 1, so their geometric mean is 1, “no change”, while one benchmark became 100 times slower. Show the individual ratios.
The choice of benchmarks is a choice of weights: adding three near-copies of one benchmark gives its behavior three votes.
Raw times and rates need other means. For rates measured on equal amounts of work, such as operations per second, total work divided by total time is the harmonic mean of the rates; for programs run equally often, the total time is the sum of their times.
Questions answered
Why is it often preferable to an arithmetic mean for speedup ratios?
The geometric mean, the th root of the product of numbers, is often preferable for speedup ratios because ratios combine by multiplication, and the geometric mean treats a doubling and a halving as opposite changes of equal size. As a result it gives consistent answers whichever way the ratios are written: the geometric mean of the reversed ratios (new time over old time instead of old over new) is exactly the reciprocal. And when results are normalized to a reference machine, the ranking of two systems does not depend on which reference was chosen. The arithmetic mean has neither property. For example, speedups of 2 and 0.5 have arithmetic mean 1.25, and the reversed ratios 0.5 and 2 also have arithmetic mean 1.25, so each system appears 25% faster than the other; the geometric mean is in both directions.
The geometric mean answers the question “what is the typical multiplicative change per benchmark, with every benchmark counted equally”. If the question is how much faster a fixed workload runs as a whole, divide the total old time by the total new time instead. In both cases show the individual ratios, because a single large regression can disappear inside a summary.
Related entries: Effect size (§11.24), Ratio of aggregates versus aggregate of ratios (§11.40), Sample mean (§11.12).