1
Fork 0
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:
Devyn Cairns 2024-07-28 05:15:55 -07:00 committed by GitHub
parent 54546c8bf2
commit 6d6a157600
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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)
}