Paul Jarc writes:
> Sam writes:
> > [EMAIL PROTECTED] writes:
> > > On Solaris an empty program issues some 19 system calls including
> > > 2 opens. A write() of 1 byte surely gets lost in the noise.
> >
> > After I cleaned up the typos, I averaged .11 seconds in ten sample runs
> > (versus .14).
>
> But with what kind of distribution? Scale up your tests - many more
> writes per run. Then it'll be clearer that the effects we see are
> coming from the writes, and not from constant overhead.
The overhead is pretty clear. The reason that I had the redundant buffer
clear in the "one write" version is so that both benchmarks had the same
setup overhead.
Ok, fine, looks like I have to bury this issue once and for all. Fine.
[mrsam@ny mrsam]$ cat prog1.c
#include <stdio.h>
#define CNT 1000
int main(int argc, char **argv)
{
int i, j;
char *p;
char buf[BUFSIZ];
memset(buf, 0, sizeof(buf));
for (j=0; j<CNT; j++)
{
p=buf;
for (i=0; i<sizeof(buf); i++)
*p++=0;
write(1, buf, sizeof(buf));
}
return (0);
}
This should accurately emulate how putc buffers one character at a time,
until it's full, and write()s out the buffer.
My BUFSIZ is 8192 bytes, and that's the size of the stdio buffer.
[mrsam@ny mrsam]$ cat prog2.c
#include <stdio.h>
#define CNT 1000
int main(int argc, char **argv)
{
int i, j;
for (j=0; j<CNT; j++)
{
for (i=0; i<BUFSIZ; i++)
write(1, "", 1);
}
return (0);
}
And that, I would think, would accurately emulate the one-character-at-a-
time-because-we're-too-lazy-to-check-the-return-code "logic".
Here's the box:
[root@ny 10remove-sendmail]# uname -a
Linux ny.email-scan.com 2.2.12-20smp #1 SMP Mon Sep 27 10:34:45 EDT 1999
i686 unknown
This is a dual-Pentium box. Red Hat 6.1 distro+all the latest patches.
Ready for the benchmarks?
[mrsam@ny mrsam]$ time ./prog1 >/dev/null
0.23user 0.00system 0:00.22elapsed 102%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (76major+10minor)pagefaults 0swaps
[mrsam@ny mrsam]$ time ./prog2 >/dev/null
3.72user 6.66system 0:10.36elapsed 100%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (75major+9minor)pagefaults 0swaps
And just to make sure that we're comparing apples with apples, and that I
did not blow the logic again:
[mrsam@ny mrsam]$ ./prog1 | wc -c
8192000
[mrsam@ny mrsam]$ ./prog2 | wc -c
8192000
Ok now, so to add everything up:
[mrsam@ny mrsam]$ bc
bc 1.05
Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale=6
10.36 / .22
47.090909
So, it seems that you pay almost a 50x penalty for the convenience of not
properly checking the return code from write().
Have a nice day.
--
Sam