Change fibonacci sample to run 5 times.

This commit is contained in:
Stephen Chung 2021-03-31 16:17:26 +08:00
parent 35394e170a
commit 42fff105ea

View File

@ -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!");
}
if result != 317_811 {
print("The answer is WRONG! Should be 317,811!");
}