Path: utzoo!attcan!uunet!mcsun!ub4b!kulcs!alain From: alain@kulcs.uucp (Alain Callebaut) Newsgroups: comp.lang.prolog Subject: Re: Why is bagof so slow? Message-ID: <1974@kulcs.kulcs.uucp> Date: 28 May 90 08:12:13 GMT Reply-To: alain@kulcs.UUCP () Organization: Katholieke Universiteit Leuven, Dept. Computer Science Lines: 20 In article <2556@randvax.UUCP> Sanjai Narain writes : > In the following program, there is one fact about f, namely f(1). > Running times of two queries, each run a thousand times, are compared: > > f(X). > bagof(X,f(X),S). > > The first takes about 25ms, whereas the second about 1200ms. Why a > 40-fold difference in speed? Are there ways to speed up computation > of sets? Timings are for Quintus Prolog on a SPARC station, running > UNIX, with 16mb of main memory. If you don't need the full flexibility of bagof, you could use findall instead : that's much faster. I did the same timings, on a SPARCstation 1, with 16 MB, for BIM_Prolog 2.5. The f(X) took 10ms, the bagof 330ms and a findall 150ms. Alain Callebaut