Path: news.daimi.aau.dk!news.uni-c.dk!sunic!sunic.sunet.se!news.luth.se!eru.mt.luth.se!news.kth.se!nac.no!Norway.EU.net!dkuug!EU.net!Germany.EU.net!Dortmund.Germany.EU.net!Informatik.Uni-Dortmund.DE!marvin!nowias00 From: nowias00@marvin.informatik.uni-dortmund.de (Mark Nowiasz) Newsgroups: comp.lang.beta Subject: Re: BETA questions Date: 24 Apr 1995 08:44:58 GMT Organization: CS Department, University of Dortmund, Germany Lines: 126 Message-ID: <3nfoea$iiq@fbi-news.informatik.uni-dortmund.de> References: <3jq90s$ojp@belfort.daimi.aau.dk> <3n5eht$m2i@fbi-news.informatik.uni-dortmund.de> NNTP-Posting-Host: marvin.informatik.uni-dortmund.de X-Newsreader: TIN [version 1.2 PL2] Ole Agesen (agesen@Xenon.Stanford.EDU) wrote: : nowias00@marvin.informatik.uni-dortmund.de (Mark Nowiasz) writes: : Mark, I would be interested in seeing both of your programs. : Any chance they are small enough that you can post them? Sure, here they are.. First the BETA-Pattern : ORIGIN '~beta/basiclib/current/betaenv' -- program: descriptor -- (# p_rekursive : (# return, m : @integer enter m do (if m > 2 // true then ((m - 1 -> p_rekursive) + (m - 2 -> p_rekursive)) -> return // false then 1 -> return; if) exit return #); p_iterative : (# return : @integer; repetition : [1]@integer enter repetition.new do (if repetition.range > 2 // true then 1 -> repetition[1] -> repetition[2]; (for i : repetition.range - 2 repeat repetition[i] + repetition[i+1] -> repetition[i + 2] for); repetition[repetition.range] -> return; // false then 1 -> return; if) exit return #); value : @ integer; do 'Value : ' -> PutText; GetInt -> Abs -> value -> p_iterative -> PutInt; NewLine; value -> p_recursive -> PutInt; NewLine; #) Now the C++ - program : #include unsigned int f_recursive(unsigned m) { if (m > 2) return f_recursive(m - 1) + f_recursive(m - 2); else return 1; }; unsigned int f_iterative(unsigned m) { unsigned ret = 1; unsigned *vector = new unsigned [m]; if (vector && (m > 2)) { vector[0] = vector[1] = 1; for (unsigned i = 2; i < m; i++) vector[i] = vector[i-1] + vector[i-2]; ret = vector[m - 1]; delete [] vector; }; return ret; }; int main(int argc, char *argv[]) { unsigned value; cout << "Enter Value:"; cin >> value; cout << f_recursive(value) << endl << f_iterative(value) << endl; }; The recursive versions are the ones which I've compared, because the run-time of the iterative ones are nearly not measurable. ( << 1 second). : Another question: did you compare CPU time or real time of the two : programs? The former increases linearly with the work load, so it : may not be a good measure (unless you only run that one program). When I was running the BETA-Pattern, I was the only one working on the SUN-4. There were certain X-Processes running (like clock) but with nice-levels increased. (The average load was << 0.5). Like Unix and OS/2 the multitasking of the amiga is preemptive, but since I was the only user and there was no other task running (except, of course, the usual system-tasks and a clock program), so the loads of the two computer systems are neglectible. -- Mark =============================================================== Mark Nowiasz nowias00@marvin.informatik.uni-dortmund.de Kronenstrasse 3 44625 Herne Germany __ __ _ ,--'--`--. _ ,--',_`--_____________ |_||____--____||_| |____|==___________----` (===(======)===) (====(==========/ \\ `--' // `--'\ / \\_ ,--, _// _,--\ /----._____ `-| |-' ,'_____\--/___________`---, `__' `-.____\___________,-----' Windows : from people who brought you edlin =============================================================