From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <798e803ad46d7e986daedaa82d5ec9bf@coraid.com> From: erik quanstrom Date: Sat, 31 Mar 2007 21:32:17 -0400 To: 9fans@cse.psu.edu Subject: Re: [9fans] slow performance In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-fchdjczczxcsbuvrlijrkvkmid" Topicbox-Message-UUID: 39e90a84-ead2-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --upas-fchdjczczxcsbuvrlijrkvkmid Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit when you compiled this on plan 9, you must have either replaced stdlib.h with something else or have used ape. i substituted libbio and get almost the same performance you did on linux. i used my home cpu server, a amd64 revF 3800+. cpu% 8c -FVw t.c warning: t.c:64 set and not used: t cpu% 8l -o t t.8 cpu% time t >/tmp/xyzw 2.08u 0.05s 2.36r t i think the reason for the difference in performance is that somehow your translation of print was calling write(2) for each integer printed. assuming i understand the point of this program -- sorting a bunch of integers, i rewrote this program using an array and qsort, which should be more memory efficient and faster. here's what i get cpu% time ./u >/tmp/xyz 0.08u 0.01s 0.22r ./u - erik --upas-fchdjczczxcsbuvrlijrkvkmid Content-Disposition: attachment; filename=t.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit #include #include #include enum{ MAX = 200000, }; typedef struct Bst Bst; struct Bst{ int v; Bst *menor; Bst *maior; }; Biobuf b; Bst* pbst(Bst *t) { if(t->menor != 0) t->menor = pbst(t->menor); Bprint(&b, "%d - ", t->v); if(t->maior != 0) t->maior = pbst(t->maior); return t; } Bst* bstini(int v) { Bst *t; t = malloc(sizeof *t); t->v = v; t->maior = 0; t->menor = 0; return t; } Bst * bstadd(int v, Bst *t) { if(t == 0) t = bstini(v); else if(v >= t->v) t->maior = bstadd(v, t->maior); else t->menor = bstadd(v, t->menor); return t; } void main(void) { Bst *t; int i; Binit(&b, 1, OWRITE); t = 0; srand(time(0)); for(i = 0; i < MAX; i++) t = bstadd(rand()%1000, t); t = pbst(t); exits(""); } --upas-fchdjczczxcsbuvrlijrkvkmid Content-Disposition: attachment; filename=u.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit #include #include #include enum{ MAX = 200000, }; int intcmp(void *a, void *b) { return *((int*)a)-*((int*)b); } void main(void) { Biobuf b; int *t, i; Binit(&b, 1, OWRITE); t = malloc(MAX*sizeof *t); srand(time(0)); for(i = 0; i < MAX; i++) t[i] = rand()%1000; qsort(t, MAX, sizeof *t, intcmp); for(i = 0; i < MAX; i++) Bprint(&b, " - %d", t[i]); exits(""); } --upas-fchdjczczxcsbuvrlijrkvkmid--