Skip to content

Commit

Permalink
feat(benchmarks): add benchmark for the file loader
Browse files Browse the repository at this point in the history
  • Loading branch information
timonv committed Jun 23, 2024
1 parent ef7dcea commit 477a284
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 1 deletion.
193 changes: 193 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["swiftide", "examples"]
members = ["swiftide", "examples", "benchmarks"]
resolver = "2"
19 changes: 19 additions & 0 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "benchmarks"
version = "0.0.0"
publish = false
edition = "2021"

[dev-dependencies]
tokio = { version = "1.0", features = ["full"] }
swiftide = { path = "../swiftide/", features = ["all"] }
tracing-subscriber = "0.3"
serde_json = "1.0"
criterion = { version = "0.5.1", features = ["html_reports"] }
anyhow = "1.0"
futures-util = "0.3"

[[bench]]
name = "fileloader"
path = "fileloader.rs"
harness = false
26 changes: 26 additions & 0 deletions benchmarks/fileloader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use anyhow::Result;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use futures_util::stream::TryStreamExt;
use swiftide::{ingestion::StreamExt, traits::Loader};

async fn run_fileloader(num_files: usize) -> Result<usize> {
let mut total_nodes = 0;
let mut stream = swiftide::loaders::FileLoader::new(".")
.with_extensions(&["rs"])
.into_stream()
.take(num_files);

while stream.try_next().await?.is_some() {
total_nodes += 1;
}
assert!(total_nodes == num_files);
Ok(total_nodes)
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("load_1", |b| b.iter(|| run_fileloader(black_box(1))));
c.bench_function("load_10", |b| b.iter(|| run_fileloader(black_box(10))));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 477a284

Please sign in to comment.