Back to .md Directory

Benchmarks

Documents how to run, compare, and interpret Criterion benchmarks for a Rust LSP project's parsers, caches, and version utilities.

May 2, 2026
0 downloads
1 views
ai
View source

What this file does

Documents how to run, compare, and interpret Criterion benchmarks for a Rust LSP project's parsers, caches, and version utilities.

When to use it

  • You need to benchmark Rust code with Criterion
  • You want to measure parsing performance across multiple file formats
  • You need to compare benchmark results against a saved baseline
  • You are setting up CI to track performance regressions

Assumes this stack

RustCriterion.rscargo bench

Benchmarks

This project uses Criterion for benchmarking.

Running Benchmarks

All Benchmarks

cargo bench --package dependi-lsp --bench benchmarks

Specific Benchmark Group

# Parser benchmarks only
cargo bench --package dependi-lsp --bench benchmarks -- parsers

# Cache benchmarks only
cargo bench --package dependi-lsp --bench benchmarks -- cache

# Version utils benchmarks only
cargo bench --package dependi-lsp --bench benchmarks -- version

Save Baseline for Comparison

# Save current results as baseline
cargo bench --package dependi-lsp --bench benchmarks -- --save-baseline main

# Compare against saved baseline
cargo bench --package dependi-lsp --bench benchmarks -- --baseline main

Using the Helper Script

./run-benchmarks.sh              # Run all benchmarks
./run-benchmarks.sh parsers      # Run parser benchmarks only
./run-benchmarks.sh --baseline   # Save results as baseline
./run-benchmarks.sh --compare    # Compare against baseline

Benchmark Suites

Parsing Benchmarks (parsers)

Measures parsing performance for all supported dependency file formats at different scales (10, 50, 100 dependencies).

BenchmarkDescription
cargo_toml/{N}Parse Cargo.toml with N dependencies
package_json/{N}Parse package.json with N dependencies
requirements_txt/{N}Parse requirements.txt with N dependencies
go_mod/{N}Parse go.mod with N dependencies
composer_json/{N}Parse composer.json with N dependencies
csproj/{N}Parse .csproj (NuGet) with N dependencies
pubspec_yaml/{N}Parse pubspec.yaml (Dart) with N dependencies
gemfile/{N}Parse Gemfile (Ruby) with N dependencies

Cache Benchmarks (cache)

Measures cache operations at different entry counts (100, 1000, 10000 for memory; 100, 1000 for SQLite).

BenchmarkDescription
cache/memory/get_hit/{N}Memory cache hit with N entries
cache/memory/get_miss/{N}Memory cache miss with N entries
cache/memory/insert/{N}Memory cache insert with N entries
cache/sqlite/get_hit/{N}SQLite cache hit with N entries
cache/sqlite/get_miss/{N}SQLite cache miss with N entries
cache/sqlite/insert/{N}SQLite cache insert with N entries

Version Utils Benchmarks (version_utils)

Measures prerelease detection performance across all supported ecosystems.

BenchmarkDescription
is_prerelease/rustRust prerelease detection (10 versions)
is_prerelease/npmnpm prerelease detection (10 versions)
is_prerelease/pythonPython prerelease detection (10 versions)
is_prerelease/goGo prerelease detection (10 versions)
is_prerelease/phpPHP prerelease detection (10 versions)
is_prerelease/dartDart prerelease detection (10 versions)
is_prerelease/nugetNuGet prerelease detection (10 versions)

VersionInfo Benchmarks (version_info)

Measures operations on the VersionInfo struct.

BenchmarkDescription
is_version_yanked_hitYanked check with hit (100 yanked versions)
is_version_yanked_missYanked check with miss (100 yanked versions)
is_version_yanked_with_prefixYanked check with version prefix (^, ~)

Performance Targets

Based on typical usage patterns:

OperationTargetRationale
Parse 50-dep Cargo.toml<5msShould be instant for user
Parse 100-dep package.json<10msLarger files still fast
Memory cache hit<1µsHashMap lookup is O(1)
Memory cache miss<1µsHashMap lookup is O(1)
SQLite cache hit<500µsConnection pool + query
SQLite cache miss<500µsConnection pool + query
Prerelease detection (10 versions)<1µsSimple string operations

Viewing Results

After running benchmarks, HTML reports are generated at:

target/criterion/report/index.html

Reports include:

  • Performance distribution plots
  • Comparison with previous runs
  • Statistical analysis
  • Regression detection

CI Integration

Benchmarks can be integrated into CI workflows. See .github/workflows/benchmarks.yml for an example configuration that:

  • Runs benchmarks on push/PR to main
  • Stores results as artifacts
  • Compares against baseline

References

What's inside

4 benchmark suites, 8 commands, 1 helper script, 1 performance target table, 1 CI reference

Change this for your project

  • Replace dependi-lsp with your own package name in all cargo bench commands
  • Replace ./run-benchmarks.sh with your own script path or remove that section
  • Replace .github/workflows/benchmarks.yml with your CI workflow file path

Where it goes

Keep it in your repository where the agent or team that needs it will read it.

Worth borrowing

  • Grouping benchmarks by subsystem (parsers, cache, version_utils) for focused runs
  • Using --save-baseline and --baseline flags to track performance over time

Related Documents