Skip to content

Commit

Permalink
Add Hanoi benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bcarlet committed Aug 30, 2023
1 parent a7a0759 commit 0d2f423
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions benchmarks/core/hanoi.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Three-disk Tower of Hanoi puzzle.
#
# Moves are printed in order, one on each line, where a move `src dst` indicates
# that the top disk from rod `src` should be moved to rod `dst`.

@hanoi (disk: int, src: int, dst: int, spare: int) {
zero: int = const 0;
nonneg: bool = ge disk zero;
br nonneg .then .else;
.then:
one: int = const 1;
above: int = sub disk one;
call @hanoi above src spare dst;
print src dst;
call @hanoi above spare dst src;
.else:
ret;
}

@main {
disk: int = const 2;
src: int = const 0;
dst: int = const 2;
spare: int = const 1;
call @hanoi disk src dst spare;
}
7 changes: 7 additions & 0 deletions benchmarks/core/hanoi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0 2
0 1
2 1
0 2
1 0
1 2
0 2
1 change: 1 addition & 0 deletions benchmarks/core/hanoi.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 100
2 changes: 2 additions & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The current benchmarks are:
* `fizz-buzz`: The infamous [programming test][fizzbuzz].
* `function_call`: For benchmarking the overhead of simple function calls.
* `gcd`: Calculate Greatest Common Divisor (GCD) of two input positive integer using [Euclidean algorithm][euclidean_into].
* `hanoi`: Print the solution to the 3-disk [Tower of Hanoi][hanoi] puzzle.
* `loopfact`: Compute *n!* imperatively using a loop.
* `mandelbrot`: Generates a really low resolution, ascii, [mandelbrot set][mandelbrot].
* `mat-inv` : Calculates the inverse of a 3x3 matrix and prints it out.
Expand Down Expand Up @@ -78,3 +79,4 @@ Credit for several of these benchmarks goes to Alexa VanHattum and Gregory Yaune
[uparrow]: https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation
[riemann]: https://en.wikipedia.org/wiki/Riemann_sum
[mandelbrot]: https://en.wikipedia.org/wiki/Mandelbrot_set
[hanoi]: https://en.wikipedia.org/wiki/Tower_of_Hanoi

0 comments on commit 0d2f423

Please sign in to comment.