mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-07-30 13:47:46 +00:00

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.
17 lines
344 B
Text
17 lines
344 B
Text
#!/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)
|
|
}
|