{
  "id": 10124393,
  "title": "Measuring How Cost Scales by Counting Instead of Timing",
  "url": "https://urgent.news/2026/09/27/measuring-how-cost-scales-by-counting-instead-of-timing",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-27T03:00:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/megapixel99/measuring-how-cost-scales-by-counting-instead-of-timing-lp3"
  },
  "original_language": "en",
  "account": "This story explores the concept of measuring computational complexity by counting operations instead of measuring elapsed time. Traditionally, complexity tools like PyPI's big-O estimates or npm's big-o-calculator measure the time it takes for a function to execute with growing input sizes. However, these tools can still produce imprecise results due to factors like standard error and noise.\n\nThe article introduces a new tool called countfn, which instead of measuring time, counts the number of reads, writes, and calls performed by a given function. By providing a function, a set of input sizes, and a way to generate the inputs, countfn reports how the computational work scales with the input size. The tool is implemented in both Python and JavaScript, allowing for cross-language comparisons.\n\nThe key advantages of countfn are that it provides consistent results regardless of the hardware or software environment, and it produces a clear ladder of complexity with error bars, making the results more reliable and interpretable. The tool counts three main types of operations: reads (element access), writes (element assignment), and calls (invocations of wrapped functions). Comparisons are treated separately to avoid conflating different types of operations.\n\nThe article presents several examples demonstrating the effectiveness of countfn. For instance, it shows that insertion sort has a quadratic time complexity, as the count of operations grows proportionally to n². The tool accurately measures this complexity even on different platforms, with no significant variation between Python and JavaScript.\n\nThe author also discusses the limitations of countfn. While it provides valuable insights into the computational complexity of an algorithm, it does not directly measure the actual running time of the code. Instead, it focuses on counting the fundamental operations that contribute to the overall complexity. This distinction is important because two algorithms with the same count of operations can still exhibit different performance characteristics due to factors like cache behavior.\n\nThe story concludes by highlighting the tool's robustness and its ability to catch discrepancies across different implementations and environments. By counting operations instead of measuring time, countfn provides a more reliable and consistent way to analyze the complexity of algorithms, helping developers make informed decisions when choosing or designing algorithms for their applications.",
  "summary": "Code: Megapixel99/countfn Every empirical complexity tool I could find on either registry measures elapsed time. PyPI's big-O estimates the class from execution time, and npm's big-o-calculator times growing inputs and reports the \"probable\" complexity; neither can refuse to answer. countfn counts operations instead: hand it a function, a ladder of input sizes, and a builder for the inputs, and…",
  "key_points": [
    "Countfn tool counts operations (reads, writes, calls) instead of measuring time",
    "Provides consistent complexity results across hardware/software environments",
    "Demonstrates quadratic time complexity for insertion sort across Python and JavaScript"
  ],
  "editors_take": "Shifting from timing to counting operations provides a more reliable method for analyzing algorithmic complexity, yielding consistent results across different environments and platforms, and enabling more informed development decisions.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}