# iRules runtime calculator

> Turn iRule timing statistics into real runtime, CPU cost per request, and maximum requests per second.

- Tool: https://ronutz.com/en/tools/f5-irules-runtime-calculator
- Family: Networking

---

## What it does

Paste the timing statistics from `tmsh show ltm rule <name> field-fmt`, give your platform's clock speed and core count, and this tool reproduces the four tables of DevCentral's long-standing iRules Runtime Calculator spreadsheet, entirely in the browser. For every event, and for the rule as a whole, it shows a best, typical, and worst case (the minimum, average, and maximum cycles) across four views: raw CPU cycles, runtime in microseconds, the CPU percentage a single request costs, and the maximum requests per second the rule can sustain. Nothing is sent anywhere.

## The measurement it reads

The `timing` command records, per event, the total executions and the cycles consumed as a minimum, average, and maximum. With `field-fmt`, that appears as blocks carrying `avg-cycles`, `min-cycles`, `max-cycles`, and `total-executions` (often abbreviated, like `43.0K`, which the tool expands). The classic one-line form, `HTTP_REQUEST 729 total 0 fail 0 abort | Cycles (min, avg, max) = (3693, 3959, 53936)`, is also accepted. Since version 11.5.0 timing is on by default. **Average is the column to trust.** Maximum is inflated because the first run of a freshly edited rule includes one-time compile-time optimization, and operating-system scheduling adds overhead at least once per tick; timing itself carries a margin of error of roughly 70 to 100 cycles. Push a large, representative load (ten thousand requests or more) and clear the statistics once after the first hit.

## How the numbers are derived

Everything flows from one figure the spreadsheet calls Cycles per second, which it computes as cores times clock in MHz times one million, straight from `/proc/cpuinfo`; that is the default here, and an optional override accepts a platform-specific number. From it: runtime in microseconds is cycles times one million divided by Cycles per second; the CPU percentage per request is cycles divided by Cycles per second; and the maximum requests per second is Cycles per second divided by cycles. The Total row sums the per-event cycles and derives its microseconds, percentage, and requests from that sum. One caveat the tool restates: these figures assume the work spreads across all cores under CMP, so if a rule modifies a global variable and is demoted to a single core, recompute with a core count of one.

## Standards and references

- [DevCentral — Generate the iRules Runtime Calculator Excel Spreadsheet with the Python SDK](https://community.f5.com/kb/technicalarticles/generate-the-irules-runtime-calculator-excel-spreadsheet-with-the-python-sdk/285509) - the calculator and its downloadable spreadsheet: Cycles/Sec as cores x MHz x 1,000,000, the field-fmt event statistics (avg/min/max-cycles, total-executions), and the table formulas reproduced here (cycles summed; microseconds = cycles x 1e6 / CyclesPerSec; % CPU = cycles / CyclesPerSec; max requests/sec = CyclesPerSec / cycles), each with min/avg/max, verified against the workbook's shipped example
- [DevCentral — Intermediate iRules: Evaluating Performance](https://community.f5.com/kb/technicalarticles/intermediate-irules-evaluating-performance/290352) - the timing command's Cycles (min, avg, max) output, average being the reliable metric, and discarding the compile-inflated maximum
- [F5 clouddocs — iRules timing command](https://clouddocs.f5.com/api/irules/timing.html) - timing syntax and scope and on-by-default since 11.5.0

## Related reading

- [iRules performance: cycles, timing, and the runtime calculator](https://ronutz.com/en/learn/irules-performance-and-timing.md): How iRules actually execute inside TMM (a Tcl interpreter compiling to bytecode), what the timing command measures, why average cycles is the reliable number and maximum is discarded, and how to turn cycles into real runtime, CPU cost per request, and maximum requests per second.
- [iRules: choosing between if, switch, class match, and static arrays](https://ronutz.com/en/learn/irules-branching-and-lookups.md): When an iRule has to match one value against many and act, there are four common tools: chained if, switch, a data group with class match, and a directly-indexed static:: array. F5 has actually ranked them for speed. Here is that ranking, and the two questions that decide which one you should reach for.
- [Loops and lists in iRules, and why they block](https://ronutz.com/en/learn/irules-loops-and-lists.md): iRules support foreach, for, and while, and most of Tcl's list commands. But loops run inline in a single-threaded TMM, so a large loop per request stalls that connection. Here is which loop to use, which list commands you actually have, and why foreach is the one to reach for first.
