mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-08-16 17:00:32 +03:00
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:
parent
bfd2af7106
commit
0d70dbddd5
24
benchmarks/fibonacci.nu
Normal file
24
benchmarks/fibonacci.nu
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user