# Benchmarking short inputs


The `shortbench` tool supports benchmarking multiple functions:
- `validate_utf8` (default)
- `utf8_length_from_latin1`
- `utf16_length_from_utf8`
- `utf32_length_from_utf8`
- `count_utf8`




```bash
# Build the tool
cmake -B build -D SIMDUTF_BENCHMARKS=ON
cmake --build build

# List available functions
./build/benchmarks/shortbench --list

# Benchmark validate_utf8 on README.md (default function)
./build/benchmarks/shortbench README.md

# Benchmark utf8_length_from_latin1 with custom max size
./build/benchmarks/shortbench --function utf8_length_from_latin1 --max-size 256 somefile.txt

# Benchmark all functions
./build/benchmarks/shortbench --all


# Get help
./build/benchmarks/shortbench --help
```

and then process the result with a script.

The tool outputs a table with columns for:
- Size (input bytes)
- Total Time (ns)
- Time/Byte (ns)
- Error (%) - timing variability estimate
- Cycles/Byte, Insns/Byte, Insns/Cycle (when performance counters available)

Example output:
```
Size       Total Time (ns)    Time/Byte (ns)    Err%    Cycles/Byte     Ins/Byte        Ins/Cycle      
----------------------------------------------------------------------------------------------------------------
1          ....     
...
```

This complements the existing `benchmark` tool which focuses on larger inputs and transcoding operations. The `shortbench` tool is particularly useful for analyzing performance characteristics of functions on small inputs where overhead and startup costs are significant.

You can then use the Python script `shortinputplots.py`. You may need to install `matplotlib`:

```bash
pip install matplotlib
```

Or use uv: 

```bash
uv run --with=matplotlib scripts/shortinputplots.py
````



This script reads the output file generated by the shortbench benchmark
and generates plots for each function showing total time and time per unit
against input size.

Usage:

1. Run the shortbench benchmark to generate output.txt in the benchmarks directory:
    build/benchmarks/shortbench --all > output.txt
2. Execute this script: python scripts/shortinputplots.py output.txt

