Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!usc!randvax!narain From: narain@randvax.UUCP (Sanjai Narain) Newsgroups: comp.lang.prolog Subject: Why is bagof so slow? Keywords: bagof, setof Message-ID: <2556@randvax.UUCP> Date: 27 May 90 05:09:51 GMT Organization: Rand Corp., Santa Monica, Ca. Lines: 25 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. Thanks for any response. Sanjai Narain time_b(T):-statistics(runtime,_),test_b(1000),statistics(runtime,[_,T]). time_c(T):-statistics(runtime,_),test_c(1000),statistics(runtime,[_,T]). test_b(0). test_b(N):-bagof(U,f(U),S),N1 is N-1, test_b(N1). test_c(0). test_c(N):-f(X),N1 is N-1,test_c(N1). f(1).