seekable stdin
Gyepi SAM
gyepi at praxis-sw.com
Thu Dec 9 23:31:23 CET 2004
On Thu, Dec 09, 2004 at 02:33:34PM -0700, Michael Gale wrote:
> I would rather not use the Perl one as a file is executed for each piece
> of mail ... so perl would constantly have to be started ... if it was a
> daemon that would be ok ...
This line of thinking comes up ever so often, but really needs to be examined.
On my system, /bin/sh is a link to /bin/bash, which is 58K in size, versus 14K
for perl. Perhaps you should write your filter in perl ;)
Honestly, if you were looking for optimizations, I would look at file IO and
data copying.
> How would the C program you have work ? Would I just have to execute it
> via the script ??
The C program is attached. Just compile it and put it in a reasonable
location. Then invoke it from your shell script.
Note that it will complain and exit with a non-zero code if
stdin is not seekable.
Just for kicks, I compared the perl and C versions. As expected the C version
is faster; by a factor of 4. But an extra 2.4 seconds per 1000 emails is not a
big deal either.
[gyepi at nome gyepi]$ time sh -c 'for i in `seq 1 1000`;do src/misc/rewind-stdin
< /dev/null;done'
real 0m0.515s
user 0m0.197s
sys 0m0.318s
[gyepi at nome gyepi]$ time sh -c 'for i in `seq 1 1000`;do perl -e "seek
STDIN,0,0" </dev/null;done'
real 0m2.366s
user 0m1.346s
sys 0m1.019s
-Gyepi
-------------- next part --------------
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
if (fseek(stdin, 0, 0) == - 1){
perror(argv[0]);
exit(1);
}
exit(0);
}
/*
Local Variables
compile-command: gcc -o rewind-stdin rewind-stdin.c
End:
*/
More information about the Bogofilter
mailing list