liveBook · Manning

Performance

As explained in Advanced Algorithms and Data Structures

An evaluation metric is a quantitative measure of the quality or performance of an algorithm's result.

A faster algorithm is not always the better choice. Performance must be measured against the job at hand: how long operations take, how much memory they use, and—when results can be approximate—how good those results are. Start by naming the operation or output that matters, then compare alternatives under the same relevant conditions. section 3.5.3 section 11.3.1

Use different measures for different questions:

  • Running time describes the cost of operations as inputs grow. Compare the operations an application actually performs, not just a structure’s headline complexity. section 2.5.1 section 14.4.3
  • CPU profiling measures a particular implementation on particular test data. It can reveal costs that an asymptotic bound or structural measure, such as tree height, does not settle. section 3.5.3
  • Memory and result quality are separate considerations. A Bloom filter’s operation times can be examined alongside the precision of `contains`; clustering needs a measure of output quality as well as an analysis of computational cost. section 4.9 section 12.5

When the input changes the winner

CPU profiling of insertion and removal found a randomized treap slower than a BST for random, unbounded integer keys: insertion took almost twice the cumulative CPU time, and removal 3.5 times as much. With random keys restricted to [0, 1000], the BST’s height grew linearly and the comparison reversed: BST insertion took eight times as long as treap insertion, with removal showing almost a 15-fold treap speed-up. Treat either result as evidence about the tested implementations and workloads, not a universal ranking. section 3.5.3

For an analytical estimate, count the work in each repeated operation and state the input variables. K-means, for example, takes O(m·k·n·d) time for at most m iterations, k clusters, n points, and d dimensions, plus O(n+k) extra memory. That estimate answers a different question from profiling elapsed CPU time. section 12.2.3 section 3.5.3

Quality when clusters cannot be judged by eye

Customer segmentation using annual income and monthly spending illustrates why output quality needs deliberate evaluation. In higher dimensions, visual inspection is difficult; without feature scaling, the larger-valued feature can dominate Euclidean distance. An elbow-method procedure tests candidate cluster counts, runs k-means repeatedly for each count, and records the minimum intra-cluster distance from those runs. section 12.5

In a time-limited nearest-neighbor service, average speed may help serve more requests, while worst-case speed may help ensure requests finish before a deadline. If data growth makes exact search too slow, sharding or an approximate approach may help, but approximation trades some result accuracy for speed. Choose the measure—and the compromise—that matches the constraint. section 11.3.1

How Advanced Algorithms and Data Structures covers it

How deep it goes
Develops asymptotic time and space estimates, implementation-specific CPU profiling, and clustering evaluation; notes that profiling results need not generalize.
Examples
Compares BSTs with randomized treaps under different key distributions, estimates k-means costs, and tests cluster counts with the elbow method.
What it assumes
Assumes basic algorithms and data structures; points to introductory big-O analysis and separate classification-metric background.
What you can do after
Evaluate/understand performance by matching complexity estimates, measured costs, and output-quality measures to the workload and its constraints.
How it connects
Connects big-O notation, CPU profiling, memory usage, priority queues, Bloom filters, nearest-neighbor search, and clustering evaluation metrics.

Also explained in

Compare how 40 books explain performance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.