benchmarks: pkg-funcs vs. modules

This commit is contained in:
DavHau 2023-08-07 13:50:27 +02:00
parent 7b96349dd4
commit deb25a354f
3 changed files with 117 additions and 0 deletions

17
misc/benchmarks/benchmark.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -eou pipefail
export NUM_PKGS=${1:-1000}
# measure date ini milliseconds
echo -e "\nBenchmarking ${NUM_PKGS}x builtins.derivaton via pkg-funcs"
time nix eval --impure -f ./builtins-derivation-modules-vs-pkg-func.nix --json pkg-funcs > /dev/null
echo -e "\nBenchmarking ${NUM_PKGS}x builtins.derivaton via modules"
time nix eval --impure -f ./builtins-derivation-modules-vs-pkg-func.nix --json modules > /dev/null
echo -e "\nBenchmarking ${NUM_PKGS}x mkDerivation via pkg-funcs"
time nix eval --impure -f ./mkDerivation-modules-vs-pkg-func.nix --json pkg-funcs > /dev/null
echo -e "\nBenchmarking ${NUM_PKGS}x mkDerivation via modules"
time nix eval --impure -f ./mkDerivation-modules-vs-pkg-func.nix --json modules > /dev/null

View File

@ -0,0 +1,49 @@
{dream2nixSource ? ../..}: let
dream2nix = import dream2nixSource;
nixpkgs = import dream2nix.inputs.nixpkgs {};
lib = nixpkgs.lib;
_callModule = module:
nixpkgs.lib.evalModules {
specialArgs.dream2nix = dream2nix;
specialArgs.packageSets.nixpkgs = nixpkgs;
modules = [module dream2nix.modules.drv-parts.core];
};
# like callPackage for modules
callModule = module: (_callModule module).config.public;
numPkgs = lib.toInt (builtins.getEnv "NUM_PKGS");
pkg-funcs = lib.genAttrs (map toString (lib.range 0 numPkgs)) (
num:
derivation {
name = "hello-${num}";
version = "2.12.1";
system = "x86_64-linux";
builder = "/bin/sh";
args = ["sh" "-c" "echo hello-${num} > $out"];
}
);
modules = lib.genAttrs (map toString (lib.range 0 numPkgs)) (
num:
callModule {
imports = [
dream2nix.modules.drv-parts.builtins-derivation
];
name = "hello-${num}";
version = "2.12.1";
builtins-derivation = {
system = "x86_64-linux";
builder = "/bin/sh";
args = ["sh" "-c" "echo hello-${num} > $out"];
};
}
);
in {
inherit
pkg-funcs
modules
;
}

View File

@ -0,0 +1,51 @@
{dream2nixSource ? ../..}: let
dream2nix = import dream2nixSource;
nixpkgs = import dream2nix.inputs.nixpkgs {};
lib = nixpkgs.lib;
_callModule = module:
nixpkgs.lib.evalModules {
specialArgs.dream2nix = dream2nix;
specialArgs.packageSets.nixpkgs = nixpkgs;
modules = [module dream2nix.modules.drv-parts.core];
};
# like callPackage for modules
callModule = module: (_callModule module).config.public;
numPkgs = lib.toInt (builtins.getEnv "NUM_PKGS");
pkg-funcs = lib.genAttrs (map toString (lib.range 0 numPkgs)) (
num:
nixpkgs.stdenv.mkDerivation rec {
pname = "hello-${num}";
version = "2.12.1";
src = nixpkgs.fetchurl {
url = "mirror://gnu/hello/hello-${version}.tar.gz";
sha256 = "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA=";
};
doCheck = false;
}
);
modules = lib.genAttrs (map toString (lib.range 0 numPkgs)) (num:
callModule rec {
imports = [
dream2nix.modules.drv-parts.mkDerivation
];
name = "hello-${num}";
version = "2.12.1";
deps.stdenv = nixpkgs.stdenv;
mkDerivation = {
src = nixpkgs.fetchurl {
url = "mirror://gnu/hello/hello-${version}.tar.gz";
sha256 = "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA=";
};
};
});
in {
inherit
pkg-funcs
modules
;
}