From 0d70dbddd5a945414eb43581ba5e536a3d26bd0b Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Thu, 11 Jul 2024 04:03:36 -0700 Subject: [PATCH] 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`. --- benchmarks/fibonacci.nu | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 benchmarks/fibonacci.nu diff --git a/benchmarks/fibonacci.nu b/benchmarks/fibonacci.nu new file mode 100644 index 0000000..5012867 --- /dev/null +++ b/benchmarks/fibonacci.nu @@ -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) +}