---
description: Benchmarking guidelines for skia-rs performance testing
globs: ["**/bench/**", "**/benches/**", "crates/skia-rs-bench/**"]
alwaysApply: false
---

# Benchmarking

## Using the Benchmark System

```bash
# Run all benchmarks
cargo bench -p skia-rs-bench

# Run specific suite
cargo bench -p skia-rs-bench --bench core_benchmarks

# Quick validation
cargo bench -p skia-rs-bench -- --test
```

## Writing Benchmarks

```rust
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

fn bench_example(c: &mut Criterion) {
    let mut group = c.benchmark_group("Example");

    group.bench_function("operation", |b| {
        b.iter(|| {
            // Use black_box to prevent optimization
            black_box(some_operation())
        })
    });

    group.finish();
}

criterion_group!(benches, bench_example);
criterion_main!(benches);
```

## Performance Targets

- Core operations (Point, Rect, Color): < 10ns
- Matrix operations: < 100ns
- Path operations: < 1µs per segment
- Canvas drawing: comparable to native Skia

## Best Practices

- Use `std::hint::black_box` to prevent compiler optimizations
- Use deterministic RNG for reproducible benchmarks
- Group related benchmarks together
- Include baseline comparisons where possible
