9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@coraid.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] slow performance
Date: Sat, 31 Mar 2007 21:32:17 -0400	[thread overview]
Message-ID: <798e803ad46d7e986daedaa82d5ec9bf@coraid.com> (raw)
In-Reply-To: <e510e47e0703311625sbc2646ay1aa80271fcd380a6@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 779 bytes --]

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

[-- Attachment #2: t.c --]
[-- Type: text/plain, Size: 831 bytes --]

#include <u.h>
#include <libc.h>
#include <bio.h>

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("");
 }

[-- Attachment #3: u.c --]
[-- Type: text/plain, Size: 435 bytes --]

#include <u.h>
#include <libc.h>
#include <bio.h>

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("");
 }

  reply	other threads:[~2007-04-01  1:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-31 16:41 pedro henrique antunes de oliveira
2007-03-31 16:48 ` Lorenzo Fernando Bivens de la Fuente
2007-03-31 16:48 ` Charles Forsyth
2007-03-31 16:57   ` pedro henrique antunes de oliveira
2007-03-31 16:55 ` W B Hacker
2007-03-31 17:12   ` Uriel
2007-03-31 19:27     ` W B Hacker
2007-03-31 23:20       ` erik quanstrom
2007-03-31 23:35         ` pedro henrique antunes de oliveira
2007-04-01  1:40           ` erik quanstrom
2007-03-31 17:15   ` Charles Forsyth
2007-03-31 18:50 ` Armando Camarero
2007-03-31 21:05   ` C H Forsyth
2007-03-31 23:25     ` pedro henrique antunes de oliveira
2007-04-01  1:32       ` erik quanstrom [this message]
2007-04-01  9:22       ` Charles Forsyth
2007-04-01  9:52         ` pedro henrique antunes de oliveira
2007-04-01  9:56           ` pedro henrique antunes de oliveira
2007-04-01 18:24 ` ron minnich
2007-04-01 19:11   ` pedro henrique antunes de oliveira
2007-04-01 19:26     ` geoff
2007-04-01 19:57       ` pedro henrique antunes de oliveira
2007-04-01 20:07         ` Charles Forsyth
2007-04-01 20:11           ` pedro henrique antunes de oliveira
2007-04-01 20:26             ` Charles Forsyth
2007-04-01 21:13             ` ISHWAR RATTAN
2007-04-02  1:52               ` pedro henrique antunes de oliveira
2007-04-01 12:08 erik quanstrom
2007-04-01 12:35 ` pedro henrique antunes de oliveira
2007-04-01 14:39   ` Uriel
2007-04-01 15:11   ` C H Forsyth
2007-04-01 17:35     ` pedro henrique antunes de oliveira
2007-04-01 18:05       ` erik quanstrom
2007-04-02  9:14 phao
2007-04-02  9:31 ` Anselm R. Garbe
2007-04-02  9:38   ` Charles Forsyth
2007-04-02  9:42     ` C H Forsyth
2007-04-02  9:45     ` Anselm R. Garbe
2007-04-02 12:49       ` pedro henrique antunes de oliveira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=798e803ad46d7e986daedaa82d5ec9bf@coraid.com \
    --to=quanstro@coraid.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).