factorial benchmark

This commit is contained in:
prod2 2022-02-05 06:10:37 +01:00
parent af2f639ccc
commit 0c4a6553ff
2 changed files with 15 additions and 0 deletions

14
benchmarks/factorial.nds Normal file
View File

@ -0,0 +1,14 @@
var fact = funct(n)
if (n > 0)
:result = n * fact(n-1)
else
:result = 1
;
var i = 0;
var res = 0;
while (i < 50000) {
res = res + fact(50);
i = i + 1;
};
print res;

View File

@ -65,6 +65,7 @@ proc DU8ptrToInt*(du8: ptr uint8): int =
cast[ptr uint16](du8)[].int
proc findConstant(ch: var Chunk, constant: NdValue): int =
# TODO, if there are a lot of constants that are different, this could be possibly slow, so either use a table lookup or only check for the last x constants
if ch.constants.len() == 0:
return -1
for i in countup(0, ch.constants.high()):