Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!Germany.EU.net!Munich.Germany.EU.net!ecrc!lyra!micha
From: micha@ecrc.de (Micha Meier)
Subject: Re: Efficiency of assertion and retraction
Message-ID: <D07001.As@ecrc.de>
Sender: news@ecrc.de
Reply-To: micha@ecrc.de
Organization: European Computer-Industry Research Centre
References: <1994Nov26.005920.26932@jarvis.cs.toronto.edu>
Date: Fri, 2 Dec 1994 16:48:00 GMT
Lines: 31

In article 26932@jarvis.cs.toronto.edu, goku@csri.toronto.edu (Samuel Yet K Hung) writes:
>I have tried to execte the following program in SCIStus Prolog 0.6 #18.
>
>test1(0).
>test1(N) :- N>0, N1 is N-1, assert(a(N)), test1(N1).
>
>test2(0).
>test2(N) :- N>0, N1 is N-1, retract(a(N)), test2(N1).
>
>test3(0).
>test3(N) :- N>0, N1 is N-1, assert(a(N)), retract(a(N)), test3(N1).
>
>When I asked test1(10000), it took around 2 second to insert the 10000 tuples.
>However, when I used test2(10000) to retract all the tuples, it took over
>15 minutes. 

Note that in test2, you have to find one clause among O(10000), whereas
in test3, there is always only one clause asserted. When your prolog system
makes no efficient indexing for dynamic predicates, the time needed
for test2 is quadratic. You can check this by exchanging assert by asserta
in test1. Then the clause to be retracted is the first one.

--Micha


---
Micha Meier			------------------------------------------------
ECRC, Arabellastr. 17		The opinions expressed above are private
D-81925 Munich 81		and may not reflect those of my employer.
micha@ecrc.de, Tel. +49-89-92699-108, Fax  +49-89-92699-170

