From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] Calling vac from C
Date: Fri, 20 Feb 2009 10:41:15 -0500 [thread overview]
Message-ID: <a118bfa1b7624fc83a8dd72e4a0b2036@quanstro.net> (raw)
In-Reply-To: <dfa0f256-7137-4e47-8970-68c659c0dcc7@x10g2000yqk.googlegroups.com>
[-- Attachment #1: Type: text/plain, Size: 952 bytes --]
> I believe that
> 1) Its too much trouble parsing the output everytime.
i don't buy that. that takes very little code. since you
have evidently already written the code, the cost
is zero.
(if you're worried about runtime, i measure parsing
time at 338ns on a core i7 920. cf. attached digestspd.c)
> 2) Calling some function from an included library will be faster.
maybe. are you sure that it matters? i measure
base fork/exec latency on a 1.8ghz xeon5000 at 330µs.
(files served from the fileserver, not a ram disk.)
the attached fork.c and nop.c were used to do the
measurement. i measure vac throughput at ~3mb/s
for small files from a brand new venti running from a
ramdisk. the venti was tiny with 5mb isect and 100mb
arenas, and empty. at that rate, 330µs will cost you
1038 bytes, or 0.3%.
remember that dynamic linking isn't free. that cost
assumes that dynamic linking is free, and it is not.
- erik
[-- Attachment #2: digestspd.c --]
[-- Type: text/plain, Size: 815 bytes --]
#include <u.h>
#include <libc.h>
#include <libsec.h>
static int
nibble(int c)
{
if(c >= '0' && c <= '9')
return c - '0';
if(c < 0x20)
c += 0x20;
if(c >= 'a' && c <= 'f')
return c - 'a'+10;
return 0xff;
}
static void
bindigest(char *s, uchar *t)
{
int i;
if(strlen(s) != 2*SHA1dlen)
sysfatal("bad digest %s", s);
for(i = 0; i < SHA1dlen; i++)
t[i] = nibble(s[2*i])<<4 | nibble(s[2*i + 1]);
}
static char *vs = "vac:da6b4b5549383cffc1b5691d824fc4bd381f0f6b";
void
main(void)
{
int i, n;
uchar score[SHA1dlen];
uvlong t0, t1;
n = 1000*1000;
t0 = nsec();
for(i = 0; i < n; i++){
if(strncmp(vs, "vac:", 4) == 0)
bindigest(vs + 4, score);
else
sysfatal("bad digest");
}
t1 = nsec();
print("%g\n", 1.*(t1 - t0)/(1.*n));
exits("");
}
[-- Attachment #3: fork.c --]
[-- Type: text/plain, Size: 381 bytes --]
#include <u.h>
#include <libc.h>
char *argv[] = {"nop", 0};
void
main(void)
{
int i, n;
uvlong t0, t1;
n = 10000;
t0 = nsec();
for(i = 0; i < n; i++)
switch(fork()){
case 0:
exec(*argv, argv);
_exits("exec");
case -1:
sysfatal("fork");
default:
free(wait());
}
t1 = nsec();
print("%g\n", 1.*(t1 - t0)/(1.*n));
exits("");
}
[-- Attachment #4: nop.c --]
[-- Type: text/plain, Size: 70 bytes --]
#include <u.h>
#include <libc.h>
void
main(void)
{
exits("");
}
next prev parent reply other threads:[~2009-02-20 15:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-19 9:53 anooop.anooop
2009-02-19 12:55 ` erik quanstrom
2009-02-20 9:53 ` anooop.anooop
2009-02-20 15:41 ` erik quanstrom [this message]
2009-02-20 16:17 ` Uriel
2009-02-20 16:47 ` erik quanstrom
2009-02-24 6:10 ` Ben Calvert
2009-02-24 15:54 erik quanstrom
2009-02-24 16:15 ` Roman V. Shaposhnik
2009-02-24 16:22 erik quanstrom
[not found] <ac072e66c823fd6d649593efec9e221b@quanstro.net>
2009-02-24 16:32 ` Roman V. Shaposhnik
2009-02-24 17:01 erik quanstrom
[not found] <c9aea65e7f058933edc0a22e931ea675@quanstro.net>
2009-02-24 17:17 ` Roman V. Shaposhnik
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=a118bfa1b7624fc83a8dd72e4a0b2036@quanstro.net \
--to=quanstro@quanstro.net \
--cc=9fans@9fans.net \
/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).