diff --git a/benchmark.sh b/benchmark.sh new file mode 100755 index 000000000..5708df6a7 --- /dev/null +++ b/benchmark.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +set -euo pipefail +set -x + +callNix () { + nix \ + --experimental-features "nix-command flakes" \ + --store /tmp/nix \ + "$@" +} + +callBuild () { + callNix \ + eval --impure --file "$THINGTOBENCH" drvPath \ + "$@" +} +getCompletions () { + NIX_GET_COMPLETIONS=6 callNix build "github:NixOS/nixpkgs?rev=ad0d20345219790533ebe06571f82ed6b034db31#firef" "$@" +} +runSearch () { + callNix search "github:NixOS/nixpkgs?rev=ad0d20345219790533ebe06571f82ed6b034db31" firefox "$@" +} + +noCache () { + "$@" --option eval-cache false +} +coldCache () { + if [[ -e ~/.cache/nix/eval-cache-v2 || -e ~/.cache/nix/eval-cache-v3 ]]; then + echo "Error: The cache should be clean" + exit 1 + fi + "$@" +} + +run_all () { + + mkdir -p "$out" + + NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=$out/eval-stats.json bash $0 noCache callBuild + + hyperfine \ + --warmup 2 \ + --export-csv "$out/result.csv" \ + --export-json "$out/result.json" \ + --export-markdown "$out/result.md" \ + --style basic \ + --prepare '' "bash $0 noCache callBuild" +} + +"$@" diff --git a/flake.nix b/flake.nix index 6c65e3406..3ef2640f4 100644 --- a/flake.nix +++ b/flake.nix @@ -294,6 +294,13 @@ ''; }; + nix-benchmarks = prev.runCommandNoCC "nix-benchmarks" { + buildInputs = [ final.nix prev.hyperfine ]; + THINGTOBENCH = ./thingToBench.nix; + NIX_PATH="nixpkgs=${prev.path}"; + } '' + bash ${./benchmark.sh} run_all + ''; }; hydraJobs = { @@ -485,7 +492,7 @@ }); packages = forAllSystems (system: { - inherit (nixpkgsFor.${system}) nix; + inherit (nixpkgsFor.${system}) nix nix-benchmarks; } // nixpkgs.lib.optionalAttrs (builtins.elem system linux64BitSystems) { nix-static = let nixpkgs = nixpkgsFor.${system}.pkgsStatic; diff --git a/thingToBench.nix b/thingToBench.nix new file mode 100644 index 000000000..b1686094e --- /dev/null +++ b/thingToBench.nix @@ -0,0 +1,12 @@ +let + # pkgs = (builtins.getFlake "github:NixOS/nixpkgs?rev=ad0d20345219790533ebe06571f82ed6b034db31").legacyPackages.x86_64-linux; + pkgs = import {}; +in + pkgs.runCommandNoCC "foo" { + buildInputs = [ + pkgs.firefox + pkgs.pandoc + # pkgs.nixosTests.xfce + ]; + } + "echo bar > $out"