Skip to content

Commit

Permalink
Merge pull request #265 from bcarlet/hanoi
Browse files Browse the repository at this point in the history
Add Hanoi benchmark
  • Loading branch information
sampsyo committed Aug 30, 2023
2 parents c34372a + 5b2408d commit e2c821f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
27 changes: 27 additions & 0 deletions benchmarks/core/hanoi.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Tower of Hanoi puzzle.
#
# Input: Number of disks.
# Output: Each move 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 (disks: int, src: int, dst: int, spare: int) {
zero: int = const 0;
pos: bool = gt disks zero;
br pos .then .else;
.then:
one: int = const 1;
above: int = sub disks one;
call @hanoi above src spare dst;
print src dst;
call @hanoi above spare dst src;
.else:
ret;
}

# ARGS: 3
@main (disks: int) {
src: int = const 0;
dst: int = const 2;
spare: int = const 1;
call @hanoi disks 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: 99
2 changes: 2 additions & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 *n*-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 @@ -79,4 +80,5 @@ 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
[euler]: https://en.wikipedia.org/wiki/E_(mathematical_constant)

0 comments on commit e2c821f

Please sign in to comment.