1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-30 13:47:46 +00:00
nu_scripts/benchmarks/fibonacci.nu
Devyn Cairns 0d70dbddd5
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`.
2024-07-11 06:03:36 -05:00

24 lines
611 B
Text

#!/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)
}