nixir/tests/benchmark/medium.nix
NotAShelf 3347699a8c
tests/benchmark: make benchmark cases... bigger
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Iabd307b475f6568cff4d1ae6e5ae56ef6a6a6964
2026-02-23 02:26:45 +03:00

75 lines
1.3 KiB
Nix

let
# Recursive factorial
factorial = n:
if n <= 1
then 1
else n * factorial (n - 1);
# Fibonacci sequence generator
fib = n:
if n <= 1
then n
else fib (n - 1) + fib (n - 2);
# List concatenation test
range = start: end:
if start >= end
then []
else [start] ++ range (start + 1) end;
# Curried function application
add = x: y: x + y;
add5 = add 5;
# Complex computation
compute = x: y: let
a = x * 2;
b = y + 10;
c = a * b;
in
c / 2;
# Data structures
numbers = range 1 11;
# Nested attribute operations
base = {
config = {
enable = true;
value = 42;
};
data = {
items = [1 2 3];
};
};
extended =
base
// {
config =
base.config
// {
extra = "test";
multiplied = base.config.value * 2;
};
computed = base.config.value + 100;
};
# Recursive attrset with selections
recursive = rec {
x = 10;
y = x * 2;
z = y + x;
result = z * 3;
final = result + x;
};
in {
fact5 = factorial 5;
fib7 = fib 7;
sum15 = add5 10;
computed = compute 10 20;
inherit numbers extended;
deepValue = extended.config.multiplied;
recursiveResult = recursive.result;
recursiveFinal = recursive.final;
}