Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Recursive Fibonacci Benchmark #357

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions benchmarks/core/fib_recursive.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ARGS: 10
@main(n: int) {
v0: int = id n;
result: int = call @fib v0;
print result;
}

@fib(x: int): int {
v1: int = id x;
v2: int = const 0;
v3: bool = eq v1 v2;
br v3 .then.0 .else.0;
.then.0:
v4: int = const 0;
ret v4;
.else.0:
v6: int = id x;
v7: int = const 1;
v8: bool = eq v6 v7;
br v8 .then.5 .else.5;
.then.5:
v9: int = const 1;
ret v9;
.else.5:
v10: int = id x;
v11: int = const 1;
v12: int = sub v10 v11;
f1: int = call @fib v12;
f1: int = id f1;
v13: int = id x;
v14: int = const 2;
v15: int = sub v13 v14;
f2: int = call @fib v15;
f2: int = id f2;
v16: int = id f1;
v17: int = id f2;
v18: int = add v16 v17;
ret v18;
}
1 change: 1 addition & 0 deletions benchmarks/core/fib_recursive.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
55
1 change: 1 addition & 0 deletions benchmarks/core/fib_recursive.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 2693
1 change: 1 addition & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The current benchmarks are:
* `up-arrow`: Computes [Knuth's up arrow][uparrow] notation, with the first argument being the number, the second argument being the number of Knuth's up arrows, and the third argument being the number of repeats.
* `vsmul`: Multiplies a constant scalar to each element of a large array. Tests the performance of vectorization optimizations.
* `reverse`: Compute number with reversed digits (e.g. 123 -> 321).
* `fib_recursive`: Computes the *n*th Fibonacci number using recursion, where `fib(n) = fib(n-1) + fib(n-2)`, with base cases `fib(0) = 0` and `fib(1) = 1`. Demonstrates recursive function calls and branching.

Credit for several of these benchmarks goes to Alexa VanHattum and Gregory Yauney, who implemented them for their [global value numbering project][gvnblog].

Expand Down