2020-04-13 17:38:10 +02:00
|
|
|
// This script calculates the n-th Fibonacci number using a really dumb algorithm
|
|
|
|
// to test the speed of the scripting engine.
|
|
|
|
|
2021-03-31 10:17:26 +02:00
|
|
|
const target = 28;
|
2020-04-13 17:38:10 +02:00
|
|
|
|
|
|
|
fn fib(n) {
|
|
|
|
if n < 2 {
|
|
|
|
n
|
|
|
|
} else {
|
|
|
|
fib(n-1) + fib(n-2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-31 10:17:26 +02:00
|
|
|
print("Running Fibonacci(28) x 5 times...");
|
2020-04-13 17:38:10 +02:00
|
|
|
print("Ready... Go!");
|
|
|
|
|
2021-03-31 10:17:26 +02:00
|
|
|
let result;
|
2020-05-13 05:56:48 +02:00
|
|
|
let now = timestamp();
|
|
|
|
|
2021-03-31 10:17:26 +02:00
|
|
|
for n in range(0, 5) {
|
|
|
|
result = fib(target);
|
|
|
|
}
|
2020-04-13 17:38:10 +02:00
|
|
|
|
2021-04-04 17:22:45 +02:00
|
|
|
print(`Finished. Run time = ${now.elapsed} seconds.`);
|
2020-05-13 05:56:48 +02:00
|
|
|
|
2021-04-04 17:22:45 +02:00
|
|
|
print(`Fibonacci number #${target} = ${result}`);
|
2020-04-13 17:38:10 +02:00
|
|
|
|
2021-03-31 10:17:26 +02:00
|
|
|
if result != 317_811 {
|
|
|
|
print("The answer is WRONG! Should be 317,811!");
|
|
|
|
}
|