git.delta.rocks / jrsonnet / refs/commits / edb8e7e9a329

difftreelog

perf use mimalloc in benches

krynvswzYaroslav Bolyukin2026-04-25parent: #e87511f.patch.diff
in: master

1 file changed

modifiedtests/benches/cpp_test_suite.rsdiffbeforeafterboth
before · tests/benches/cpp_test_suite.rs
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);
after · tests/benches/cpp_test_suite.rs
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,6	manifest::{BlackBoxFormat, JsonFormat},7	stack::limit_stack_depth,8	trace::PathResolver,9};1011#[global_allocator]12static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;1314fn bench_entry(c: &mut Criterion, path: &Path) {15	c.bench_function(16		path.file_name()17			.expect("file path")18			.to_str()19			.expect("name is utf-8"),20		|b| {21			let _stack = limit_stack_depth(200_000);2223			let mut s = State::builder();2425			s.context_initializer(jrsonnet_stdlib::ContextInitializer::new(26				PathResolver::Absolute,27			))28			.import_resolver(FileImportResolver::new(vec![]));2930			let s = s.build();31			let _s = s.enter();3233			b.iter(|| {34				let imported = s.import(path).expect("evaluated");35				let res = apply_tla(&HashMap::new(), imported).expect("tla applied");36				black_box(res.manifest(JsonFormat::cli(3)).expect("manifested"));37			});38		},39	);40}41fn criterion_benchmark(c: &mut Criterion) {42	for entry in read_dir("go_builtin_benchmarks").expect("dir exists") {43		let entry = entry.expect("entry is valid");44		assert!(entry.metadata().expect("entry is valid").is_file());45		bench_entry(c, &entry.path());46	}47	for entry in read_dir("cpp_perf_tests").expect("dir exists") {48		let entry = entry.expect("entry is valid");49		assert!(entry.metadata().expect("entry is valid").is_file());50		bench_entry(c, &entry.path());51	}52	for entry in read_dir("cpp_benchmarks").expect("dir exists") {53		let entry = entry.expect("entry is valid");54		if entry.path().extension().is_none_or(|e| e != "jsonnet") {55			continue;56		}57		assert!(entry.metadata().expect("entry is valid").is_file());58		bench_entry(c, &entry.path());59	}60}6162criterion_group!(benches, criterion_benchmark);63criterion_main!(benches);