mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-07-29 21:27:47 +00:00
Add recursive fibonacci benchmark (#924)
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.
This commit is contained in:
parent
54546c8bf2
commit
6d6a157600
1 changed files with 17 additions and 0 deletions
17
benchmarks/fibonacci-recursive.nu
Normal file
17
benchmarks/fibonacci-recursive.nu
Normal file
|
@ -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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue