On 10/21/2014 05:14 PM, Eric Kow wrote:
> Hi everybody,
>
> I'm trying to track down some performance problems with my program (it
> slows down and eats more memory as it loops through a large number of
> files, each input being essentially independent of each other).
>
> Using the statistics procedure, I notice that the number of 'clauses'
> grows on each iteration.
>
> I notice also, as in this code snippet below, that retracting the
> clauses does not make a difference
> (as a sanity check, not asserting them in the first place keeps them
> constant).
>
> Is this to be expected?
> Are there any space/performance implications for my program if it does a
> lot of asserting and retracting of clauses?
>
> Thanks!
>
> Eric
>
> --------------8<----------------------
>
> maxcount(10000000).
>
> main :- dynamic(foo/1),
> do_loop(0).
dynamic/1 is a directive. SWI-Prolog also accepts it as
a goal, but it is still better style to use
:- dynamic foo/1.
> do_loop(N) :- maxcount(Max), N >= Max.
> do_loop(N) :-
> statistics(clauses, Count),
> write(N), write('\t'), write(Count), nl,
> assert(foo(N)),
> retractall(foo),
This retracts foo/0, while you assert to foo/1. retractall/1 on an
undefined predicate is not at error, but creates the predicate as
dynamic. If you do
retractall(foo(_)),
it runs nicely in constant space. Note that foo/0 and foo/1 are two
completely distinct predicates.
Cheers --- Jan
> Np1 is N+1,
> do_loop(Np1).
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
swi-prolog+...@googlegroups.com
> <mailto:
swi-prolog+...@googlegroups.com>.
> Visit this group at
http://groups.google.com/group/swi-prolog.
> For more options, visit
https://groups.google.com/d/optout.