🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #836

Why is bagof so slow?

#836
From: Sanjai Narain
Date: Sun, 27 May 1990 05:09
25 lines
1098 bytes
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).
Technical Details
Message-ID: <2556@randvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!usc!randvax!narain

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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