From 3270817b9053cc0d656bf9f8522e81a2917b3036 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Fri, 2 Sep 2022 15:02:19 -0400 Subject: test(tvix/eval): Add attr merge benchmarks Add a quick couple of benchmarks for merging attribute sets, large and small. Change-Id: I26940a9cf4e0d30e3d9eb07a7b8c366ca4072ca3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6286 Tested-by: BuildkiteCI Reviewed-by: tazjin Autosubmit: grfn --- tvix/eval/Cargo.lock | 1 + tvix/eval/Cargo.toml | 1 + tvix/eval/benches/eval.rs | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'tvix') diff --git a/tvix/eval/Cargo.lock b/tvix/eval/Cargo.lock index 05bcd8ccd2bc..4732d1b00220 100644 --- a/tvix/eval/Cargo.lock +++ b/tvix/eval/Cargo.lock @@ -874,6 +874,7 @@ version = "0.1.0" dependencies = [ "criterion", "dirs", + "itertools", "path-clean", "pretty_assertions", "rnix", diff --git a/tvix/eval/Cargo.toml b/tvix/eval/Cargo.toml index 21c224347309..32fa9e25737d 100644 --- a/tvix/eval/Cargo.toml +++ b/tvix/eval/Cargo.toml @@ -23,6 +23,7 @@ rev = "614e7d4641e83ab7eb321d9ac5e3d12985f9f3ba" criterion = "0.3.6" test-generator = "0.3.0" pretty_assertions = "1.2.1" +itertools = "0.10.3" [features] # Enables running the Nix language test suite from the original C++ diff --git a/tvix/eval/benches/eval.rs b/tvix/eval/benches/eval.rs index a05c04f03e29..9be381e0f803 100644 --- a/tvix/eval/benches/eval.rs +++ b/tvix/eval/benches/eval.rs @@ -1,9 +1,25 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use itertools::Itertools; use tvix_eval::interpret; fn eval_literals(c: &mut Criterion) { c.bench_function("int", |b| b.iter(|| black_box(interpret("42", None)))); } -criterion_group!(benches, eval_literals); +fn eval_merge_attrs(c: &mut Criterion) { + c.bench_function("merge small attrs", |b| { + b.iter(|| black_box(interpret("{ a = 1; b = 2; } // { c = 3; }", None))) + }); + + c.bench_function("merge large attrs with small attrs", |b| { + let large_attrs = format!( + "{{{}}}", + (0..10000).map(|n| format!("a{n} = {n};")).join(" ") + ); + let expr = format!("{large_attrs} // {{ c = 3; }}"); + b.iter(move || black_box(interpret(&expr, None))) + }); +} + +criterion_group!(benches, eval_literals, eval_merge_attrs); criterion_main!(benches); -- cgit 1.4.1