I’m using SWI-Prolog 8.0.3. When benchmarking code wuth time/1, I get strange results. For demonstration purpose, I use good old naive Fibonacci.
fib(0, 1) :- !.
fib(1, 1) :- !.
fib(N, F) :-
N > 1,
N1 is N-1,
N2 is N-2,
fib(N1, F1),
fib(N2, F2),
F is F1+F2.
Now I try to see how long it takes.
?- time(fib(20,F)).
gives me
% 43,782 inferences, 0.000 CPU in 17170420255948800.000 seconds (0% CPU, Infinite Lips)
F = 10946.
And it sure didn’t take as long… Worse:
?- time(fib(30,F)).
gives
% 5,385,073 inferences, 0.656 CPU in -1404464184216781100.000 seconds (?% CPU, 8205826 Lips)
F = 1346269.
And that looks like an integer overflow of sorts. So, how to make sense of these numbers?
On a not entirely unrelated issue - is there space/1, too?
cheers
Harald