bench: add benchmarks to show off string perf improvements

Change-Id: I6d032706e1e8b6fa39502276ac2018cb69de6ce5
This commit is contained in:
Mel Zuser 2024-05-15 21:26:15 -07:00
parent be7a07d87a
commit d973508e17
2 changed files with 23 additions and 0 deletions

View file

@ -50,6 +50,10 @@ cases=(
[rebuild]="{BUILD}/bin/nix $flake_args eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'"
[rebuild-lh]="GC_INITIAL_HEAP_SIZE=10g {BUILD}/bin/nix eval $flake_args --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'"
[parse]="{BUILD}/bin/nix $flake_args eval -f bench/nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix"
[substr100k]="{BUILD}/bin/nix eval --no-eval-cache -f bench/substring.nix --apply 'f: f.bench 100000'"
[substr200k]="{BUILD}/bin/nix eval --no-eval-cache -f bench/substring.nix --apply 'f: f.bench 200000'"
[substr300k]="{BUILD}/bin/nix eval --no-eval-cache -f bench/substring.nix --apply 'f: f.bench 300000'"
[substr400k]="{BUILD}/bin/nix eval --no-eval-cache -f bench/substring.nix --apply 'f: f.bench 400000'"
)
defaultBenches=(

19
bench/substring.nix Normal file
View file

@ -0,0 +1,19 @@
# Tests stringLength and substring performance
with builtins;
{
bench =
baseStrLen:
let
# a big string
baseStr = concatStringsSep "" (genList (_: "x") baseStrLen);
# a way to force the values
sum = ns: foldl' (acc: n: acc + n) 0 ns;
forceOpTimes =
range: # Int
op: # Int -> Int
sum (genList (ix: op ix) range);
benchOp = ix: stringLength (substring ix 1 baseStr);
in
forceOpTimes baseStrLen benchOp;
}