bench: add benchmarks to show off string perf improvements
Change-Id: I6d032706e1e8b6fa39502276ac2018cb69de6ce5
This commit is contained in:
parent
be7a07d87a
commit
d973508e17
|
@ -50,6 +50,10 @@ cases=(
|
||||||
[rebuild]="{BUILD}/bin/nix $flake_args eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'"
|
[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'"
|
[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"
|
[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=(
|
defaultBenches=(
|
||||||
|
|
19
bench/substring.nix
Normal file
19
bench/substring.nix
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue