From 6d6a157600fb742b186f28c174d2f12f09118061 Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Sun, 28 Jul 2024 05:15:55 -0700 Subject: [PATCH] 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. --- benchmarks/fibonacci-recursive.nu | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 benchmarks/fibonacci-recursive.nu diff --git a/benchmarks/fibonacci-recursive.nu b/benchmarks/fibonacci-recursive.nu new file mode 100644 index 0000000..7910964 --- /dev/null +++ b/benchmarks/fibonacci-recursive.nu @@ -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) +}