Skip to content

Commit

Permalink
Add recursive fibonacci benchmark (#924)
Browse files Browse the repository at this point in the history
This is pretty much the least efficient reasonably simple way to
implement fibonacci in Nushell, and it's a good benchmark to profile our
custom command call performance, as this is the majority of the work
being done.

I think it may actually be good to add this and the other one to `cargo
bench` so we can track it over time, but it's also useful as a script so
it can easily be profiled.
  • Loading branch information
devyn authored Jul 28, 2024
1 parent 54546c8 commit 6d6a157
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions benchmarks/fibonacci-recursive.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env nu
# This is a much less efficient, recursive version of fibonacci that can be used to test our
# command call performance.

use std bench

def fib [n: int] {
match $n {
0 => 0,
1 => 1,
$n => { (fib ($n - 1)) + (fib ($n - 2)) },
}
}

def main [] {
print (bench { 0..20 | each { |n| fib $n } } | reject times)
}

0 comments on commit 6d6a157

Please sign in to comment.