벤치마크 설계

Vais Benchmark Suite Design

개요

Vais 컴파일러의 성능을 측정하고 회귀를 감지하는 벤치마크 스위트입니다.

목표

  1. 컴파일 성능 측정: 렉싱, 파싱, 타입체킹, 코드젠 각 단계별 시간 측정
  2. 런타임 성능 측정: 생성된 코드의 실행 성능 측정
  3. 회귀 감지: CI에서 자동으로 성능 저하 감지
  4. 비교 분석: 버전 간, 최적화 레벨 간 비교

아키텍처

benches/
├── Cargo.toml              # Criterion 의존성
├── compile_bench.rs        # 컴파일 벤치마크
├── runtime_bench.rs        # 런타임 벤치마크
├── fixtures/               # 테스트용 Vais 소스 파일
│   ├── fibonacci.vais      # 재귀 함수
│   ├── sort.vais           # 정렬 알고리즘
│   ├── string_ops.vais     # 문자열 연산
│   ├── struct_heavy.vais   # 구조체 연산
│   └── complex.vais        # 복합 벤치마크
└── results/                # 벤치마크 결과 저장

벤치마크 종류

1. 컴파일 벤치마크

벤치마크측정 대상입력
lexer_throughput초당 토큰 처리량다양한 크기 소스
parser_throughput초당 AST 노드 생성복잡도별 소스
typecheck_time타입 검사 시간제네릭, 트레이트 포함
codegen_timeIR 생성 시간함수/구조체 수별
full_compile전체 컴파일 시간실제 프로젝트 규모

2. 런타임 벤치마크

벤치마크측정 대상비교 대상
fibonacci재귀 성능C, Rust
quicksort메모리 접근 패턴C, Rust
string_concat문자열 처리C, Rust
struct_alloc힙 할당 성능C, Rust
closure_call클로저 호출 오버헤드Rust

3. 최적화 벤치마크

최적화 레벨측정 항목
O0기준선 (최적화 없음)
O1기본 최적화 효과
O2표준 최적화 효과
O3공격적 최적화 효과

구현 세부사항

Criterion 설정

use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};

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

    for fixture in ["fibonacci", "sort", "complex"] {
        let source = fs::read_to_string(format!("benches/fixtures/{}.vais", fixture)).unwrap();

        group.bench_with_input(
            BenchmarkId::new("lex", fixture),
            &source,
            |b, s| b.iter(|| tokenize(s)),
        );

        group.bench_with_input(
            BenchmarkId::new("parse", fixture),
            &source,
            |b, s| b.iter(|| parse(s)),
        );
    }

    group.finish();
}

메모리 벤치마크

// 메모리 사용량 측정 (선택적)
#[cfg(feature = "memory-bench")]
fn memory_benchmark(c: &mut Criterion) {
    // jemalloc 또는 custom allocator 사용
}

CI 통합

# .github/workflows/bench.yml
benchmark:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
    - name: Run benchmarks
      run: cargo bench --bench compile_bench -- --save-baseline main
    - name: Compare with baseline
      run: cargo bench --bench compile_bench -- --baseline main

결과 형식

JSON 출력

{
  "version": "0.0.1",
  "timestamp": "2026-01-20T12:00:00Z",
  "benchmarks": {
    "compile/lex/fibonacci": {
      "mean": 125.3,
      "std_dev": 2.1,
      "unit": "us"
    }
  }
}

Markdown 리포트

## Benchmark Results (v0.0.1)

| Benchmark | Mean | Std Dev | Change |
|-----------|------|---------|--------|
| compile/lex | 125μs | ±2.1μs | - |
| compile/parse | 340μs | ±5.2μs | - |

회귀 감지 기준

변화율판정액션
< -5%개선로그만
-5% ~ +5%정상무시
+5% ~ +10%경고PR 코멘트
> +10%실패CI 실패

의존성

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }

실행 방법

# 전체 벤치마크 실행
cargo bench

# 특정 벤치마크만 실행
cargo bench --bench compile_bench

# HTML 리포트 생성
cargo bench -- --save-baseline current

# 베이스라인과 비교
cargo bench -- --baseline main