# Benchmarks

`mix bam.bench --records 500` ran on 2026-11-30. The figures below are copied from that run. They are one machine, one OTP, and one small synthetic file.

| Item | Value |
| --- | --- |
| Elixir | 1.18.4 |
| OTP | 28 |
| Architecture | `aarch64-apple-darwin25.2.0` |
| Schedulers | 10 |
| samtools | 1.25, htslib 1.25 |
| Records | 500 |
| Fixture bytes | 2393 |
| Compression | level 1, with a BAI sidecar |
| Reference | `chr1`, length 1,000,000 |
| Read shape | 8 bp `M`, positions 0, 1, 2, … |

Each iteration opens the file, reads, and closes it. The stream iteration counts every record. The region iteration asks for `chr1` positions `[0, 200)`.

Benchee `time: 2`, `memory_time: 1`:

| Job | ips | average | deviation | median | 99th % | average memory |
| --- | --- | --- | --- | --- | --- | --- |
| stream | 1.28 K | 0.78 ms | ±18.14% | 0.77 ms | 1.06 ms | 1.34 MB |
| region | 0.92 K | 1.09 ms | ±39.99% | 1.03 ms | 3.45 ms | 1.26 MB |

Benchee reported region as 1.39× slower than stream (+0.31 ms) and as 0.94× the stream memory (−0.08432 MB). Memory is Benchee's per-iteration measurement of the benchmark function, which includes the open file and the decoded records. It is not a resident-set figure for a large production file.

No parallel inflate was measured. The 500-record file is too small to decide whether `:zlib` is the limiter on a whole-genome BAM. That comparison stays open.

## This library and pysam

`mix run bench/python_vs_elixir.exs -- --records 500 --iterations 40 --warmup 5` ran on 2026-11-30, after the Benchee table above. It writes the same 500-record file (2393 bytes, compression level 1, BAI sidecar) and times both readers on that file. Each iteration opens, reads, and closes. `stream` counts every record. `region` counts `chr1` positions `[0, 200)`. The script discards 5 warmup iterations, then reports the mean of 40. Both sides counted 500 records in `stream` and 200 in `region`.

| Item | Value |
| --- | --- |
| Elixir | 1.18.4 |
| OTP | 28 |
| Python | 3.12.9 |
| pysam | 0.24.1 |
| Architecture | `aarch64-apple-darwin25.2.0` |
| Records | 500 |
| Fixture bytes | 2393 |
| Iterations | 40, after 5 warmup |

| Job | Elixir mean | pysam mean |
| --- | --- | --- |
| stream | 0.751 ms | 0.232 ms |
| region | 1.182 ms | 0.126 ms |

pysam 0.24.1 calls HTSlib. These means are not the Benchee numbers above: Benchee ran for 2 seconds and also measured memory. This table is one short loop on one small file. It is not a claim about a whole-genome BAM.

Re-run with `mix run bench/python_vs_elixir.exs -- --records N` and replace this section with that output. If `pysam` is not installed, the script prints `pysam: not run` and this section should say that instead of a time. Do not copy a number from a run that did not happen.
