mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 14:55:05 +00:00
bench: WGSL parsing
This commit is contained in:
parent
231da54cd7
commit
b05f648842
@ -37,6 +37,10 @@ hlsl-out = []
|
||||
span = ["codespan-reporting"]
|
||||
validate = []
|
||||
|
||||
[[bench]]
|
||||
name = "criterion"
|
||||
harness = false
|
||||
|
||||
# MSRV warnings:
|
||||
# - arbitrary 1.0.3 requires Rust-1.51
|
||||
# - bitflags 1.3 requires Rust-1.46
|
||||
@ -59,6 +63,7 @@ pp-rs = { version = "0.2.1", optional = true }
|
||||
hexf-parse = { version = "0.2.1", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.3", features = ["html_reports"] }
|
||||
diff = "0.1"
|
||||
ron = "0.7"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
46
benches/criterion.rs
Normal file
46
benches/criterion.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use criterion::*;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
fn gather_inputs(folder: &str, extension: &str) -> Vec<String> {
|
||||
let mut list = Vec::new();
|
||||
let read_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join(folder)
|
||||
.read_dir()
|
||||
.unwrap();
|
||||
for file_entry in read_dir {
|
||||
match file_entry {
|
||||
Ok(entry) => match entry.path().extension() {
|
||||
Some(ostr) if &*ostr == extension => {
|
||||
let input = fs::read_to_string(entry.path()).unwrap_or_default();
|
||||
list.push(input);
|
||||
}
|
||||
_ => continue,
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!("Skipping file: {:?}", e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
list
|
||||
}
|
||||
|
||||
fn frontends(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("tests/in");
|
||||
group.bench_function("wgsl", |b| {
|
||||
let inputs = gather_inputs("tests/in", "wgsl");
|
||||
let mut parser = naga::front::wgsl::Parser::new();
|
||||
b.iter(move || {
|
||||
for input in inputs.iter() {
|
||||
parser.parse(input).unwrap();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn validation(_c: &mut Criterion) {}
|
||||
|
||||
fn backends(_c: &mut Criterion) {}
|
||||
|
||||
criterion_group!(criterion, frontends, validation, backends,);
|
||||
criterion_main!(criterion);
|
Loading…
Reference in New Issue
Block a user