diff --git a/examples/benchmarks/README.md b/examples/benchmarks/README.md index 3564414e..54644eea 100644 --- a/examples/benchmarks/README.md +++ b/examples/benchmarks/README.md @@ -1,55 +1,66 @@ -# benchmarks +# (No Fib) Benchmarks -Write validators in the `validators` folder, and supporting functions in the `lib` folder using `.ak` as a file extension. +This folder contains a set of benchmarks inspired and ported from the [plutus-benchmarks](https://github.com/IntersectMBO/plutus/tree/master/plutus-benchmark/nofib#plutus-nofib-benchmarks), written in Haskell. The idea is to provide benchmarks which can capture more realistic patterns and behaviours than usual "Fibonacci" benchmarks often used for benchmarking applications but falling short in capturing real-world scenarios. -For example, as `validators/always_true.ak` +Note that the primary use-case of those benchmarks is to compare Aiken with itself across compiler versions. As optimizations get implemented, it comes as a supplimentary means to assess their impact. -```gleam -validator { - fn spend(_datum: Data, _redeemer: Data, _context: Data) -> Bool { - True - } -} -``` +## Summary -## Building +Results are summarized below, relatively to the previous version. For brevity, we only report versions for which there's a deviation from a previous version. -```sh -aiken build -``` + -```sh -aiken check -m foo -``` +### CPU -## Documentation +| Benchmark | `v1.0.29` | vs `v1.0.25` | vs `v1.0.23` | vs `v1.0.21` | vs `v1.0.18` | +| --- | ---: | ---: | ---: | ---: | ---: | +| `knights_100_4x4` | 71851995726 | +1.40% | +4.45% | +4.30% | +4.80% | +| `knights_100_6x6` | 159767368294 | +8.93% | +11.92% | +11.85% | +12.70% | +| `knights_100_8x8` | 319834775948 | +11.40% | +14.35% | +14.32% | +15.13% | -If you're writing a library, you might want to generate an HTML documentation for it. +### Mem -Use: - -```sh -aiken docs -``` - -## Resources - -Find more on the [Aiken's user manual](https://aiken-lang.org). +| Benchmark | `v1.0.29` | vs `v1.0.25` | vs `v1.0.23` | vs `v1.0.21` | vs `v1.0.18` | +| --- | ---: | ---: | ---: | ---: | ---: | +| `knights_100_4x4` | 172256715 | -0.48% | +5.04% | +4.90% | +5.80% | +| `knights_100_6x6` | 321712271 | +10.08% | +16.54% | +16.46% | +18.29% | +| `knights_100_8x8` | 601065675 | +14.48% | +21.30% | +21.26% | +23.15% | diff --git a/examples/benchmarks/lib/benchmarks/knights.ak b/examples/benchmarks/lib/benchmarks/knights.ak index 6aa16529..7e9374b6 100644 --- a/examples/benchmarks/lib/benchmarks/knights.ak +++ b/examples/benchmarks/lib/benchmarks/knights.ak @@ -79,7 +79,7 @@ fn done(item: (Int, ChessSet)) -> Bool { // ------------------------------------------------------------------ Fixtures -fn solution_100_6x6() { +fn solution_100_6x6() -> Solution { [ ( 0, @@ -268,7 +268,7 @@ fn solution_100_6x6() { ] } -fn solution_100_8x8() { +fn solution_100_8x8() -> Solution { [ ( 0, @@ -278,32 +278,36 @@ fn solution_100_8x8() { start: Some((1, 1)), visited: [ (3, 2), - (5, 3), - (4, 5), - (5, 7), - (7, 6), - (8, 8), - (6, 7), - (5, 5), - (3, 4), - (1, 5), - (2, 7), - (4, 8), - (3, 6), - (1, 7), - (3, 8), - (4, 6), - (6, 5), (4, 4), (5, 6), (6, 4), - (7, 2), + (8, 5), + (7, 7), + (6, 5), (8, 4), + (7, 2), + (5, 3), + (3, 4), + (4, 6), + (5, 8), + (6, 6), + (4, 5), + (3, 7), + (1, 8), + (2, 6), + (4, 7), + (5, 5), (6, 3), (5, 1), (4, 3), (3, 5), (5, 4), + (7, 3), + (8, 1), + (6, 2), + (4, 1), + (2, 2), + (1, 4), (3, 3), (2, 5), (1, 3), @@ -314,31 +318,27 @@ fn solution_100_8x8() { (7, 4), (8, 6), (7, 8), - (6, 6), - (8, 5), - (7, 7), - (5, 8), - (3, 7), - (1, 8), - (2, 6), - (1, 4), - (2, 2), - (4, 1), - (6, 2), - (8, 1), - (7, 3), + (5, 7), + (3, 8), + (1, 7), + (3, 6), + (2, 8), + (1, 6), + (2, 4), + (1, 2), + (3, 1), (5, 2), (7, 1), (8, 3), (7, 5), (8, 7), (6, 8), - (4, 7), - (2, 8), - (1, 6), - (2, 4), - (1, 2), - (3, 1), + (7, 6), + (8, 8), + (6, 7), + (4, 8), + (2, 7), + (1, 5), (2, 3), (1, 1), ], @@ -352,32 +352,36 @@ fn solution_100_8x8() { start: Some((1, 1)), visited: [ (3, 2), - (5, 3), - (4, 5), - (5, 7), - (7, 6), - (8, 8), - (6, 7), - (4, 8), - (2, 7), - (1, 5), - (3, 4), - (5, 5), - (3, 6), - (1, 7), - (3, 8), - (4, 6), - (6, 5), (4, 4), (5, 6), + (7, 7), + (8, 5), (6, 4), (7, 2), (8, 4), + (6, 5), + (5, 3), + (3, 4), + (4, 6), + (5, 8), + (6, 6), + (4, 5), + (3, 7), + (1, 8), + (2, 6), + (4, 7), + (5, 5), (6, 3), (5, 1), (4, 3), (3, 5), (5, 4), + (7, 3), + (8, 1), + (6, 2), + (4, 1), + (2, 2), + (1, 4), (3, 3), (2, 5), (1, 3), @@ -388,184 +392,101 @@ fn solution_100_8x8() { (7, 4), (8, 6), (7, 8), - (6, 6), - (8, 5), - (7, 7), - (5, 8), - (3, 7), - (1, 8), - (2, 6), - (1, 4), - (2, 2), - (4, 1), - (6, 2), - (8, 1), - (7, 3), - (5, 2), - (7, 1), - (8, 3), - (7, 5), - (8, 7), - (6, 8), - (4, 7), - (2, 8), - (1, 6), - (2, 4), - (1, 2), - (3, 1), - (2, 3), - (1, 1), - ], - }, - ), - ] -} - -fn solution_80_8x8() { - [ - ( - 0, - ChessSet { - size: 8, - move_number: 64, - start: Some((1, 1)), - visited: [ - (3, 2), - (5, 3), - (4, 5), - (5, 7), - (7, 6), - (8, 8), - (6, 7), - (5, 5), - (3, 4), - (1, 5), - (2, 7), - (4, 8), - (3, 6), - (1, 7), - (3, 8), - (4, 6), - (6, 5), - (4, 4), - (5, 6), - (6, 4), - (7, 2), - (8, 4), - (6, 3), - (5, 1), - (4, 3), - (3, 5), - (5, 4), - (3, 3), - (2, 5), - (1, 3), - (2, 1), - (4, 2), - (6, 1), - (8, 2), - (7, 4), - (8, 6), - (7, 8), - (6, 6), - (8, 5), - (7, 7), - (5, 8), - (3, 7), - (1, 8), - (2, 6), - (1, 4), - (2, 2), - (4, 1), - (6, 2), - (8, 1), - (7, 3), - (5, 2), - (7, 1), - (8, 3), - (7, 5), - (8, 7), - (6, 8), - (4, 7), - (2, 8), - (1, 6), - (2, 4), - (1, 2), - (3, 1), - (2, 3), - (1, 1), - ], - }, - ), - ( - 0, - ChessSet { - size: 8, - move_number: 64, - start: Some((1, 1)), - visited: [ - (3, 2), - (5, 3), - (4, 5), - (5, 7), - (7, 6), - (8, 8), - (6, 7), - (4, 8), - (2, 7), - (1, 5), - (3, 4), - (5, 5), - (3, 6), - (1, 7), - (3, 8), - (4, 6), - (6, 5), - (4, 4), - (5, 6), - (6, 4), - (7, 2), - (8, 4), - (6, 3), - (5, 1), - (4, 3), - (3, 5), - (5, 4), - (3, 3), - (2, 5), - (1, 3), - (2, 1), - (4, 2), - (6, 1), - (8, 2), - (7, 4), - (8, 6), - (7, 8), - (6, 6), - (8, 5), - (7, 7), - (5, 8), - (3, 7), - (1, 8), - (2, 6), - (1, 4), - (2, 2), - (4, 1), - (6, 2), - (8, 1), - (7, 3), + (5, 7), + (3, 8), + (1, 7), + (3, 6), + (2, 8), + (1, 6), + (2, 4), + (1, 2), + (3, 1), (5, 2), (7, 1), (8, 3), (7, 5), (8, 7), (6, 8), + (7, 6), + (8, 8), + (6, 7), + (4, 8), + (2, 7), + (1, 5), + (2, 3), + (1, 1), + ], + }, + ), + ( + 0, + ChessSet { + size: 8, + move_number: 64, + start: Some((1, 1)), + visited: [ + (3, 2), + (4, 4), + (6, 5), + (8, 4), + (7, 2), + (5, 3), + (3, 4), + (4, 6), + (5, 8), + (7, 7), + (5, 6), + (6, 4), + (8, 5), + (6, 6), + (4, 5), + (3, 7), + (1, 8), + (2, 6), (4, 7), + (5, 5), + (6, 3), + (5, 1), + (4, 3), + (3, 5), + (5, 4), + (7, 3), + (8, 1), + (6, 2), + (4, 1), + (2, 2), + (1, 4), + (3, 3), + (2, 5), + (1, 3), + (2, 1), + (4, 2), + (6, 1), + (8, 2), + (7, 4), + (8, 6), + (7, 8), + (5, 7), + (3, 8), + (1, 7), + (3, 6), (2, 8), (1, 6), (2, 4), (1, 2), (3, 1), + (5, 2), + (7, 1), + (8, 3), + (7, 5), + (8, 7), + (6, 8), + (7, 6), + (8, 8), + (6, 7), + (4, 8), + (2, 7), + (1, 5), (2, 3), (1, 1), ], diff --git a/examples/benchmarks/lib/benchmarks/knights/heuristic.ak b/examples/benchmarks/lib/benchmarks/knights/heuristic.ak index 2c36662d..efcfb2b1 100644 --- a/examples/benchmarks/lib/benchmarks/knights/heuristic.ak +++ b/examples/benchmarks/lib/benchmarks/knights/heuristic.ak @@ -133,11 +133,11 @@ fn possible_moves(board: ChessSet) -> List { direction_list() |> list.filter(can_move(board, _)) } -fn compare_tile(a: Tile, b: Tile) -> Ordering { - if a.1st == b.1st { - int.compare(a.2nd, b.2nd) - } else { +fn compare_chess_set(a: (Int, ChessSet), b: (Int, ChessSet)) -> Ordering { + if a.1st != b.1st { int.compare(a.1st, b.1st) + } else { + compare_list(a.2nd.visited, b.2nd.visited) } } @@ -163,37 +163,10 @@ fn compare_list(xs: List, ys: List) -> Ordering { } } -fn compare_chess_set(a: (Int, ChessSet), b: (Int, ChessSet)) -> Ordering { - if a.1st != b.1st { - int.compare(a.1st, b.1st) +fn compare_tile(a: Tile, b: Tile) -> Ordering { + if a.1st == b.1st { + int.compare(a.2nd, b.2nd) } else { - let ChessSet { - size: size_a, - move_number: move_a, - start: start_a, - visited: visited_a, - } = a.2nd - let ChessSet { - size: size_b, - move_number: move_b, - start: start_b, - visited: visited_b, - } = b.2nd - if size_a != size_b { - int.compare(size_a, size_b) - } else if move_a != move_b { - int.compare(move_a, move_b) - } else if start_a != start_b { - when start_a is { - Some(a) -> - when start_b is { - Some(b) -> compare_tile(a, b) - None -> Greater - } - None -> Less - } - } else { - compare_list(visited_a, visited_b) - } + int.compare(a.1st, b.1st) } }