From 42fff105eae7cad3e017cd3d785fb9d6a3ce02e9 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 31 Mar 2021 16:17:26 +0800 Subject: [PATCH] Change fibonacci sample to run 5 times. --- scripts/fibonacci.rhai | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/fibonacci.rhai b/scripts/fibonacci.rhai index 3455c5f6..14a35d5e 100644 --- a/scripts/fibonacci.rhai +++ b/scripts/fibonacci.rhai @@ -1,7 +1,7 @@ // This script calculates the n-th Fibonacci number using a really dumb algorithm // to test the speed of the scripting engine. -const target = 30; +const target = 28; fn fib(n) { if n < 2 { @@ -11,16 +11,20 @@ fn fib(n) { } } +print("Running Fibonacci(28) x 5 times..."); print("Ready... Go!"); +let result; let now = timestamp(); -let result = fib(target); +for n in range(0, 5) { + result = fib(target); +} print("Finished. Run time = " + now.elapsed + " seconds."); print("Fibonacci number #" + target + " = " + result); -if result != 832_040 { - print("The answer is WRONG! Should be 832,040!"); -} \ No newline at end of file +if result != 317_811 { + print("The answer is WRONG! Should be 317,811!"); +}