Skip to content
TKTail

Purpose-built scripts and the TKTail workflow - the source

methodology/METHODOLOGY.md

SHA-256 (LF line endings, as in the source ZIP): d6c89f0f13849356dab19f1b8c488cb4ca1bdfdfe518e5795e5c1e0a25a91e64 · MIT license (the benchmark suite only)

# competitive-bench-v1 - methodology

What is measured, how, and what the numbers do and do not say. Written before the published run; a change of method is
a new suite version (`competitive-bench-v2`), never silently the same name.

## 1. The rule: the same answer first

Every implementation answers every scenario once before anything is timed (`scripts/run.py`, phase *correctness*).
Its answer, normalized (`scripts/scenarios.py`), must equal the ground truth `datasets/generate.py` computed while it
wrote the data - an oracle independent of every measured implementation: the same count, the same top 10 (count
descending, then the value), the same per-minute buckets. An answer that differs is **FAILED CORRECTNESS** and is never
timed; a run that exceeds the timeout (30 minutes) is reported as **> 30 min**, never as a number. The generator makes
every top 10 unambiguous (no tie decides membership - `topIsUnambiguous` in each expected manifest).

Semantics every implementation keeps:

- Text is case-sensitive and compared as bytes / ordinal strings; the data is ASCII.
- A counted row is a log line: in the application log a line containing `ERROR`, or a record's first line carrying
  `elapsed: <number>ms`; in the W3C log a request line (`#` directive lines are not records).
- `elapsed` and `time-taken` are compared as numbers (`1000.000 >= 1000`); the W3C log's field positions come from its
  `#Fields` directive.
- Minutes are the W3C log's own time (UTC), `YYYY-MM-DDTHH:MM`.

## 2. Two cost models - never mixed

**Cold (end to end):** one process per run - start, read, answer, exit. For TKTail: start the window with the file,
connect an MCP client (`TKTail.exe mcp --stdio`), ask, receive the answer (the window is closed afterwards, outside
the time). This is "a script run per question" against "start TKTail for one question".

**Warm (investigation session):** the same question repeated in a process that is already running. The baselines run
`--repeat N+1` and report each repetition's time (the first warms the JIT / interpreter and is not counted). TKTail
has the file open and indexed (its line index - the state of a user investigating it) and one MCP session; each
repetition is one `tktail_search` to its end. A warm TKTail does **not** answer from a cache of earlier answers: every
search reads the file again.

The **session** scenario asks five questions of one incident in a row (`count-5xx`, `top-ip-5xx`, `top-uri-5xx`,
`per-minute-5xx`, `count-slow`): TKTail warm (the log open, one MCP session) against the baselines as one script run
per question. It is labeled a session benchmark.

## 3. Caches - said, not hidden

- **OS file cache: warm.** Every dataset is read by a warm-up run before the measured runs; the cache is not cleared
  (the machine has far more memory than the data). No number here is a cold-disk number.
- **TKTail's own state:** the line index of an open file (built in the background when it opens; warm runs start when
  that work has finished - CPU quiet for 2 s). Searches do not use an inverted index; there is none.
- **Regex:** TKTail compiles a pattern once per search (PCRE2 with JIT); the baselines use no regular expressions
  except the idiomatic PowerShell pipeline (`Select-String`, .NET Regex).
- **JIT / interpreter:** cold runs include runtime start-up and JIT; warm runs exclude the first repetition.

## 4. Repetitions, order, statistics

- A warm-up run per implementation and scenario (not counted), then 5 measured runs - 3 when the warm-up run took
  more than 60 s. Medians are published with minimum and maximum; spread = (max - min) / median.
- The implementations' order rotates every run (deterministically) so no one always runs first or last.
- Measured from outside the process: wall time (start to exit), CPU time (user + kernel, `GetProcessTimes`), peak
  working set (`GetProcessMemoryInfo`). Warm baselines report their own repetition times; their CPU is the process's
  total divided by the repetitions. TKTail's CPU is the window's plus the MCP bridge's; its peak working set is the
  window's.
- Throughput = dataset bytes / median time (MB = 10^6 bytes).

## 5. The implementations (code review before timing)

| Implementation | Streams? | Whole file in memory? | Regex | Buffering | Known inefficiency | Fairness |
|---|---|---|---|---|---|---|
| C# (`csharp/Program.cs`) | yes, 1 MB blocks as byte spans | no | none (vectorized `IndexOf`, `Utf8Parser`) | 1 MB, `SequentialScan` | none known; strings only for keys of matching lines | accepted |
| Python (`python/bench.py`) | yes, binary line iteration | no | none (`bytes.find`, `split`) | 1 MB | `split` of every W3C line (the idiomatic way) | accepted |
| PowerShell optimized (`powershell/bench.ps1`) | yes, `StreamReader.ReadLine` | no | none (ordinal `Contains` / `IndexOf`) | 1 MB | the interpreter's per-line cost - inherent | accepted |
| PowerShell idiomatic (`powershell/idiomatic.ps1`) | `Select-String` / `Get-Content -ReadCount 1000` stream | no | .NET Regex in `Select-String` | cmdlet defaults | an object per record (`ConvertFrom-Csv`, `Group-Object`) - inherent to the idiom | labeled a convenience baseline |
| TKTail (`tktail/tktail_driver.py`) | yes | no | PCRE2 (the number scenario's capture) | its block cache | parses all 16 W3C fields of a record for a field condition | product path (MCP) |

No implementation is multi-threaded; TKTail's search of one file runs on one thread. TKTail is measured through the
interface an AI client uses - JSON-RPC over a pipe and a bridge process included - never an internal engine call.

## 6. Fairness notes (differences that remain)

- TKTail reads a field condition through its W3C record parser (every field, its type and role); the C# baseline
  splits a line only as far as the field it needs.
- The number scenario: TKTail extracts with a regular expression's named capture (`elapsed: (?<ms>\d+(?:\.\d+)?)ms`)
  as a user would write it; the baselines find the marker and parse the digits directly.
- A cold TKTail run starts a Windows application with a window and its MCP bridge, and builds the file's line index in
  the background while it searches; a cold script starts a runtime.
- The PowerShell baselines run unchanged on 5.1 and 7; no C# is compiled into them (that would be the C# baseline).
- The isolation switch `--internal-instance-scope` gives the measured TKTail copy its own single-instance family so it
  never joins a TKTail the user runs; it changes nothing in how TKTail opens, reads or searches.

## 7. The payload scenario (what crosses the MCP boundary)

"Which 10 clients sent the most POST requests answered 503?" over the 100 MB W3C log (1,365 matches - all stored by
the search, so the full-record workflow is complete): three workflows, each checked against the ground truth.

- **A. Full records** (what TKTail 1.0.2 offered): result pages (their first fields do not include `c-ip`), then each
  record read whole (`tktail_get_record`), saved, counted by a script (`scripts/top_from_pages.py`).
- **B. Projection** (1.1.0): result pages with `"fields": ["c-ip"], "preview": false`, saved, counted by the script.
- **C. Aggregation** (1.1.0): one `tktail_search` with `"aggregate": {"groupBy": ["c-ip"], "top": 10}`.

Measured: the bytes of the tool answers (the JSON a model reads; the JSON-RPC envelope carries it twice and is not
counted), the MCP calls, the bytes saved for the script, the processes launched, the wall time. No token or money
estimate is made.

## 8. What the numbers do not say

They are this machine (recorded in `environment.json`: CPU, memory, disk, Windows build, security software), this
TKTail exe (its SHA-256), these runtimes and these implementations. They are not a ranking of languages, and a
different machine, disk or antivirus configuration gives different numbers.