git.delta.rocks / jrsonnet / refs/commits / 5fc1275a239d

difftreelog

source

tests/benches/cpp_test_suite.rs1.7 KiBsourcehistory
1use std::{collections::HashMap, fs::read_dir, hint::black_box, path::Path};23use criterion::{Criterion, criterion_group, criterion_main};4use jrsonnet_evaluator::{5	FileImportResolver, State, apply_tla, manifest::JsonFormat, trace::PathResolver,6};78fn bench_entry(c: &mut Criterion, path: &Path) {9	c.bench_function(10		path.file_name()11			.expect("file path")12			.to_str()13			.expect("name is utf-8"),14		|b| {15			let mut s = State::builder();1617			s.context_initializer(jrsonnet_stdlib::ContextInitializer::new(18				PathResolver::Absolute,19			))20			.import_resolver(FileImportResolver::new(vec![]));2122			let s = s.build();23			let _s = s.enter();2425			b.iter(|| {26				let imported = s.import(path).expect("evaluated");27				let res = apply_tla(&HashMap::new(), imported).expect("tla applied");28				black_box(res.manifest(JsonFormat::cli(3)))29			});30		},31	);32}33fn criterion_benchmark(c: &mut Criterion) {34	for entry in read_dir("go_builtin_benchmarks").expect("dir exists") {35		let entry = entry.expect("entry is valid");36		assert!(entry.metadata().expect("entry is valid").is_file());37		bench_entry(c, &entry.path());38	}39	for entry in read_dir("cpp_perf_tests").expect("dir exists") {40		let entry = entry.expect("entry is valid");41		assert!(entry.metadata().expect("entry is valid").is_file());42		bench_entry(c, &entry.path());43	}44	for entry in read_dir("cpp_benchmarks").expect("dir exists") {45		let entry = entry.expect("entry is valid");46		// Skip .gitignore47		if entry.path().extension().is_none() {48			continue;49		}50		assert!(entry.metadata().expect("entry is valid").is_file());51		bench_entry(c, &entry.path());52	}53}5455criterion_group!(benches, criterion_benchmark);56criterion_main!(benches);