The test case is not related to queues. Its only the simplest test
case that came to my mind that has assertz/1 and retract/1 in it.
The old dynamic database test case I had was fibonacci memoization,
but this tested only assertz/1. Now I wanted also a test case that tests
retract/1. Just imagine a test case that tests a little database representing
a warehouse, and articles get randomly inserted and deleted.
Mostlikely the originally posted test case is slow because retract/1
is not cutted away, and I guess its skipping some list with clauses
marked as deleted or something? For example this test case is much faster:
/* SWI-Prolog 9.3.3 */
?- time(test).
% 7,001,001 inferences, 0.000 CPU in 1.110 seconds (0% CPU, Infinite Lips)
true.
That it shows 0.0000 CPU is quite a funny bug? But it takes only 1.0
second for 1_000_000 transactions, and retract/1 is cutted away via (->)/2:
:- dynamic(foo/2).
test :-
retractall(foo(_,_)),
warehouse(1000000, 1, 18884).
warehouse(0, _, _) :- !.
warehouse(N, X, Y) :-
assertz(foo(Y, bar)),
(retract(foo(X, bar)) -> true; true),
zx81(X, Z), zx81(Y, T),
M is N-1,
warehouse(M, Z, T).
zx81(X, Y) :- Y is (X*75+74) mod 65537.