|
1 | 1 | # Benchmarks |
2 | 2 |
|
3 | | -This document records the latest benchmark run and the Python/stdlib baselines used for comparison. |
4 | | -All timings are **seconds for 20,000 runs** on the local machine; results are not directly comparable across hardware or Python versions. |
| 3 | +Compare performance between runs. All timings are **seconds for 20,000 runs**. |
5 | 4 |
|
6 | | -## How To Run |
| 5 | +## Quick Start |
7 | 6 |
|
8 | 7 | ```bash |
9 | | -PYTHONPATH=. python3.12 benchmarks/bench_types.py |
| 8 | +make bench # Run benchmarks |
| 9 | +make bench-compare # Compare with baseline |
| 10 | +make bench-baseline # Set current as baseline |
10 | 11 | ``` |
11 | 12 |
|
12 | | -Raw data is written to: |
13 | | -- `benchmarks/out/bench_results.json` |
14 | | -- `benchmarks/out/bench_profiles.json` |
15 | | - |
16 | | -## Latest Results (Local) |
17 | | - |
18 | | -**Run date:** 2026-02-04 |
19 | | -**Python:** 3.12.11 |
20 | | -**Runs:** 20,000 |
21 | | - |
22 | | -### TSRKit Types (selected) |
23 | | - |
24 | | -| Case | init_s | encode_s | decode_s | json_encode_s | json_decode_s | |
25 | | -| --- | --- | --- | --- | --- | --- | |
26 | | -| Uint | 0.008567 | 0.004479 | 0.014276 | 0.002534 | 0.008913 | |
27 | | -| U16 | 0.008530 | 0.004632 | 0.014242 | 0.002791 | 0.009892 | |
28 | | -| Bytes(var,64B) | 0.004458 | 0.010630 | 0.008252 | 0.003609 | 0.010214 | |
29 | | -| ByteArray | 0.003199 | 0.006915 | 0.006440 | 0.003522 | 0.009588 | |
30 | | -| Bits(var,64b) | 0.011615 | 0.011080 | 0.016224 | 0.007608 | 0.024439 | |
31 | | -| TypedArray[U16,10] | 0.014253 | 0.006967 | 0.017195 | 0.003189 | 0.152636 | |
32 | | -| Dictionary[String,U16] | 0.023382 | 0.061991 | 0.149705 | 0.068052 | 0.179980 | |
33 | | - |
34 | | -### Python/Stdlib Baselines (selected) |
35 | | - |
36 | | -| Case | init_s | encode_s | decode_s | |
37 | | -| --- | --- | --- | --- | |
38 | | -| PyInt(varint) | 0.002778 | 0.006405 | 0.007207 | |
39 | | -| PyU16(to_bytes) | 0.004112 | 0.003861 | 0.006797 | |
40 | | -| PyBytes(var,64B) | 0.003516 | 0.005396 | 0.005538 | |
41 | | -| PyByteArray(var,64B) | 0.003091 | 0.006694 | 0.006594 | |
42 | | -| PyBits(var,64b) | 0.006438 | 0.088161 | 0.150918 | |
43 | | -| PyArray('H',10) | 0.006611 | 0.008616 | 0.006599 | |
44 | | -| PyDict[str,U16] | 0.003587 | 0.095823 | 0.077303 | |
45 | | - |
46 | | -## Notes On Baselines |
47 | | - |
48 | | -- `PyInt(varint)`: pure-Python varint encoder/decoder (same scheme as `Uint`). |
49 | | -- `PyU16(to_bytes)`: `int.to_bytes` / `int.from_bytes` for fixed-width integers. |
50 | | -- `PyBytes(var,64B)` / `PyByteArray(var,64B)`: length-prefixed bytes (varint length). |
51 | | -- `PyBits(var,64b)`: list[bool] packed/unpacked to bytes in Python. |
52 | | -- `PyArray('H',10)`: stdlib `array('H')` with `.tobytes()` / `.frombytes()`. |
53 | | -- `PyDict[str,U16]`: sorted key encode; keys length-prefixed; values fixed 2-byte little-endian. |
| 13 | +Results: `benchmarks/out/bench_results.json` (14KB) |
| 14 | + |
| 15 | +## Workflow |
| 16 | + |
| 17 | +```bash |
| 18 | +# 1. Set baseline |
| 19 | +make bench |
| 20 | +make bench-baseline |
| 21 | + |
| 22 | +# 2. Make changes... |
| 23 | + |
| 24 | +# 3. Compare |
| 25 | +make bench |
| 26 | +make bench-compare |
| 27 | +``` |
| 28 | + |
| 29 | +## Custom runs |
| 30 | + |
| 31 | +```bash |
| 32 | +make bench ARGS="--runs 1000 --no-profile" |
| 33 | +``` |
| 34 | + |
| 35 | +## What's Tested |
| 36 | + |
| 37 | +**Types**: Integers, Bytes, Bits, Strings, Bool, Collections, Dictionary, Option, Choice, Enum, Structures |
| 38 | + |
| 39 | +**Operations**: init, encode, decode, json_encode/decode, container ops (append/extend/pop/getitem) |
0 commit comments