Add fibonacci benchmark, for fairly low-level eval performance (#892)

This is a benchmark that I created while testing IR. It's meant to
basically do only very simple operations but be running 100% Nushell
code most of the time, without any heavy lifting being done by commands,
and without any closure calls or anything like that. It seemed useful to
keep around so I'm adding it to `nu_scripts`.
This commit is contained in:
Devyn Cairns 2024-07-11 04:03:36 -07:00 committed by GitHub
parent bfd2af7106
commit 0d70dbddd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

24
benchmarks/fibonacci.nu Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env nu
# This benchmark covers the evaluation performance of some very simple, iterative Nushell code that
# doesn't require a bunch of calls into nested closures and doesn't rely on commands to do any
# heavy lifting.
#
# Originally added by @devyn to show what absolute best case performance for IR evaluation can look
# like. Not super representative of normal Nushell code.
use std bench
def fib [n: int] {
mut a = 0
mut b = 1
for _ in 2..=$n {
let c = $a + $b
$a = $b
$b = $c
}
$b
}
def main [] {
print (bench -n 1000 { 0..50 | each { |n| fib $n } } | reject times)
}