> 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
#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("");
}#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("");
}#include <u.h>
#include <libc.h>
void
main(void)
{
exits("");
}