about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-07-31T15·50+0200
committerflokli <flokli@flokli.de>2023-10-16T12·26+0000
commit652afd21b39fe7aabe81bb948ba4ba490422070d (patch)
tree0458322f24934e39a7635b53a98fceff0f3d2b2f
parentc3fad811f4ad19eaa7c1a258b7a3188cda10da92 (diff)
feat(nix-compat): add bench for aterm parsing r/6835
Change-Id: Ie9416f0046b6ee0a02096a7712cdba9cc84db4f6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9733
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Reviewed-by: Gabriel Doriath Döhler <gabriel.doriath.dohler@ens.fr>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
-rw-r--r--tvix/Cargo.lock1
-rw-r--r--tvix/Cargo.nix7
-rw-r--r--tvix/nix-compat/Cargo.toml5
-rw-r--r--tvix/nix-compat/benches/derivation_parse_aterm.rs31
4 files changed, 43 insertions, 1 deletions
diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock
index b67f70669a2a..b3b736a25be3 100644
--- a/tvix/Cargo.lock
+++ b/tvix/Cargo.lock
@@ -1430,6 +1430,7 @@ name = "nix-compat"
 version = "0.1.0"
 dependencies = [
  "bstr",
+ "criterion",
  "data-encoding",
  "futures",
  "futures-util",
diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix
index 49c3042e61fd..7710f3afdf0a 100644
--- a/tvix/Cargo.nix
+++ b/tvix/Cargo.nix
@@ -1636,7 +1636,7 @@ rec {
           "stable" = [ "csv_output" "html_reports" "async_futures" "async_smol" "async_tokio" "async_std" ];
           "tokio" = [ "dep:tokio" ];
         };
-        resolvedDefaultFeatures = [ "cargo_bench_support" "default" "plotters" "rayon" ];
+        resolvedDefaultFeatures = [ "cargo_bench_support" "default" "html_reports" "plotters" "rayon" ];
       };
       "criterion-plot" = rec {
         crateName = "criterion-plot";
@@ -4231,6 +4231,11 @@ rec {
         ];
         devDependencies = [
           {
+            name = "criterion";
+            packageId = "criterion";
+            features = [ "html_reports" ];
+          }
+          {
             name = "futures";
             packageId = "futures";
             usesDefaultFeatures = false;
diff --git a/tvix/nix-compat/Cargo.toml b/tvix/nix-compat/Cargo.toml
index 0fff23fc4421..19030612c283 100644
--- a/tvix/nix-compat/Cargo.toml
+++ b/tvix/nix-compat/Cargo.toml
@@ -24,9 +24,14 @@ futures = { version = "0.3.28", default-features = false, features = ["executor"
 lazy_static = "1.4.0"
 serde_json = "1.0"
 test-case = "2.2.2"
+criterion = { version = "0.4", features = ["html_reports"] }
 
 [dev-dependencies.test-generator]
 # This fork of test-generator adds support for cargo workspaces, see
 # also https://github.com/frehberg/test-generator/pull/14
 git = "https://github.com/JamesGuthrie/test-generator.git"
 rev = "82e799979980962aec1aa324ec6e0e4cad781f41"
+
+[[bench]]
+name = "derivation_parse_aterm"
+harness = false
diff --git a/tvix/nix-compat/benches/derivation_parse_aterm.rs b/tvix/nix-compat/benches/derivation_parse_aterm.rs
new file mode 100644
index 000000000000..4ace7d4480f4
--- /dev/null
+++ b/tvix/nix-compat/benches/derivation_parse_aterm.rs
@@ -0,0 +1,31 @@
+use std::path::Path;
+
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use nix_compat::derivation::Derivation;
+
+const RESOURCES_PATHS: &str = "src/derivation/tests/derivation_tests/ok";
+
+fn bench_aterm_parser(c: &mut Criterion) {
+    for drv in [
+        "0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv",
+        "292w8yzv5nn7nhdpxcs8b7vby2p27s09-nested-json.drv",
+        "4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv",
+        "52a9id8hx688hvlnz4d1n25ml1jdykz0-unicode.drv",
+        "9lj1lkjm2ag622mh4h9rpy6j607an8g2-structured-attrs.drv",
+        "ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv",
+        "h32dahq0bx5rp1krcdx3a53asj21jvhk-has-multi-out.drv",
+        "m1vfixn8iprlf0v9abmlrz7mjw1xj8kp-cp1252.drv",
+        "ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv",
+        "x6p0hg79i3wg0kkv7699935f7rrj9jf3-latin1.drv",
+    ] {
+        let drv_path = Path::new(RESOURCES_PATHS).join(drv);
+        let drv_bytes = &std::fs::read(drv_path).unwrap();
+
+        c.bench_function(drv, |b| {
+            b.iter(|| Derivation::from_aterm_bytes(black_box(drv_bytes)))
+        });
+    }
+}
+
+criterion_group!(benches, bench_aterm_parser);
+criterion_main!(benches);