Fix scripts.

This commit is contained in:
Stephen Chung
2021-04-16 10:33:55 +08:00
parent 8da4c0c2b2
commit c5128e15d5
3 changed files with 10 additions and 15 deletions

View File

@@ -1,7 +1,8 @@
// This script calculates the n-th Fibonacci number using a really dumb algorithm
// to test the speed of the scripting engine.
const target = 28;
const TARGET = 28;
const REPEAT = 5;
fn fib(n) {
if n < 2 {
@@ -11,19 +12,19 @@ fn fib(n) {
}
}
print("Running Fibonacci(28) x 5 times...");
print(`Running Fibonacci(28) x ${REPEAT} times...`);
print("Ready... Go!");
let result;
let now = timestamp();
for n in range(0, 5) {
result = fib(target);
for n in range(0, REPEAT) {
result = fib(TARGET);
}
print(`Finished. Run time = ${now.elapsed} seconds.`);
print(`Fibonacci number #${target} = ${result}`);
print(`Fibonacci number #${TARGET} = ${result}`);
if result != 317_811 {
print("The answer is WRONG! Should be 317,811!");