about summary refs log tree commit diff
path: root/tvix/eval/benches
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/benches')
-rw-r--r--tvix/eval/benches/eval.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/tvix/eval/benches/eval.rs b/tvix/eval/benches/eval.rs
new file mode 100644
index 000000000000..1333f5018cb3
--- /dev/null
+++ b/tvix/eval/benches/eval.rs
@@ -0,0 +1,42 @@
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use itertools::Itertools;
+#[cfg(not(target_env = "msvc"))]
+use tikv_jemallocator::Jemalloc;
+
+#[cfg(not(target_env = "msvc"))]
+#[global_allocator]
+static GLOBAL: Jemalloc = Jemalloc;
+
+fn interpret(code: &str) {
+    tvix_eval::Evaluation::new_pure().evaluate(code, None);
+}
+
+fn eval_literals(c: &mut Criterion) {
+    c.bench_function("int", |b| {
+        b.iter(|| {
+            interpret(black_box("42"));
+        })
+    });
+}
+
+fn eval_merge_attrs(c: &mut Criterion) {
+    c.bench_function("merge small attrs", |b| {
+        b.iter(|| {
+            interpret(black_box("{ a = 1; b = 2; } // { c = 3; }"));
+        })
+    });
+
+    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 || {
+            interpret(black_box(&expr));
+        })
+    });
+}
+
+criterion_group!(benches, eval_literals, eval_merge_attrs);
+criterion_main!(benches);