From d973508e1719d8f05fe6392bea04cee0695494ea Mon Sep 17 00:00:00 2001 From: Mel Zuser Date: Wed, 15 May 2024 21:26:15 -0700 Subject: [PATCH] bench: add benchmarks to show off string perf improvements Change-Id: I6d032706e1e8b6fa39502276ac2018cb69de6ce5 --- bench/bench.sh | 4 ++++ bench/substring.nix | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 bench/substring.nix diff --git a/bench/bench.sh b/bench/bench.sh index 3cc20930d..06a417fad 100755 --- a/bench/bench.sh +++ b/bench/bench.sh @@ -50,6 +50,10 @@ cases=( [rebuild]="{BUILD}/bin/nix $flake_args eval --raw --impure --expr 'with import {}; system'" [rebuild-lh]="GC_INITIAL_HEAP_SIZE=10g {BUILD}/bin/nix eval $flake_args --raw --impure --expr 'with import {}; 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=( diff --git a/bench/substring.nix b/bench/substring.nix new file mode 100644 index 000000000..696d18cac --- /dev/null +++ b/bench/substring.nix @@ -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; +}