Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!Germany.EU.net!EU.net!sun4nl!freya.let.rug.nl!vannoord
From: vannoord@let.rug.nl (Gertjan van Noord)
Subject: Re: Efficiency of assertion and retraction
Sender: news@let.rug.nl (News system at let.rug.nl)
Message-ID: <1994Nov26.133903.21283@let.rug.nl>
Date: Sat, 26 Nov 1994 13:39:03 GMT
References: <1994Nov26.005920.26932@jarvis.cs.toronto.edu>
Nntp-Posting-Host: tyr.let.rug.nl
Organization: Faculteit der Letteren, Rijksuniversiteit Groningen, NL
Lines: 29

In article <1994Nov26.005920.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. 
>
>Also,
>	:- test1(10000), test2(10000).
>took more than 15 minutes to execute.
>
>I assumed retracting tuples took much longer time than assertions. However,
>when I tried test3(10000) which also has 10000 assertions and deletions, 
>it terminated successfully in 2-3 seconds. So, why does it took such a short
>time?  Is it due to the time for the garbage collection of the free memory, 
>or is it a bug?

it is much simpler: if there are many a/1 defs, then retract leaves a
choicepoint, of course.

