Are 3B1 "pipes" really slower than molasses?
Robert E. Stampfli
res at cbnews.att.com
Sat Dec 1 04:37:47 AEST 1990
Here are some hacked up versions of Thad's send/recv pipe tester programs
which yield results an order of magnitude faster than his. As Shakespeare
would put it, "The fault, Dear Thaddeus, lies not in pipes, but in stdio..."
Rob Stampfli
att!cbnews!res
==========================================================================
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
# Makefile
# myrecv.c
# mysend.c
# mytest.sh
# pass.c
# recv.c
# send.c
# test.sh
# This archive created: Fri Nov 30 12:18:52 1990
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'Makefile'" '(169 characters)'
if test -f 'Makefile'
then
echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^ X//' << \SHAR_EOF > 'Makefile'
X
X# 3B1 makefile for pipe speed testing
X#
XCC = gcc -shlib -s
XCFLAGS = -O
X
Xall : mysend myrecv send recv pass
X
Xclean :
X rm -f *.o mysend myrecv send recv pass core a.out
SHAR_EOF
if test 169 -ne "`wc -c < 'Makefile'`"
then
echo shar: "error transmitting 'Makefile'" '(should have been 169 characters)'
fi
fi
echo shar: "extracting 'myrecv.c'" '(1025 characters)'
if test -f 'myrecv.c'
then
echo shar: "will not over-write existing file 'myrecv.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'myrecv.c'
X/* recv.c
X *
X * just receives chars from stdin until EOF for testing the speed
X * of pipes on the system.
X *
X * Thad Floryan, 26-Nov-1990
X * rewritten without stdio, Rob Stampfli 30-Nov-1990
X */
X
X#include <stdio.h>
X#include <sys/param.h> /* for def of HZ */
X#include <sys/types.h>
X#include <sys/times.h>
X
Xmain(argc)
X{
X extern long times();
X
X static char buffer[BUFSIZ*5];
X register int i;
X long startime, endtime, elapsed;
X struct tms timebuf;
X long numchrs = 0;
X
X startime = times(&timebuf); /* get start time in HZ units */
X
X while ( (i = read(0, buffer, BUFSIZ*5)) > 0 ) {
X if(argc > 1)
X printf("%d ", i);
X numchrs += i;
X }
X
X if(argc > 1)
X printf("\n");
X
X endtime = times(&timebuf); /* get completion time in HZ units */
X
X if ( (elapsed = endtime - startime) != 0L )
X {
X printf("%d characters received in %d.%03d seconds for %d CPS\n",
X numchrs,
X elapsed / HZ,
X ((elapsed % HZ) * 1000L) / HZ,
X ((numchrs * HZ) / elapsed ));
X }
X else
X {
X printf("Insufficient timer resolution for supplied input\n");
X }
X}
SHAR_EOF
if test 1025 -ne "`wc -c < 'myrecv.c'`"
then
echo shar: "error transmitting 'myrecv.c'" '(should have been 1025 characters)'
fi
fi
echo shar: "extracting 'mysend.c'" '(595 characters)'
if test -f 'mysend.c'
then
echo shar: "will not over-write existing file 'mysend.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'mysend.c'
X/* send.c
X *
X * just sends argv[1] number of characters out for testing the speed
X * of pipes on the system.
X *
X * Thad Floryan, 26-Nov-1990
X * rewritten without stdio, Rob Stampfli 30-Nov-1990
X */
X
X#include <stdio.h>
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X static char buffer[BUFSIZ];
X register int i;
X long numchrs;
X
X numchrs = atol(argv[1]); /* dismiss error checks for now */
X
X /* while ( --numchrs >= 0L ) putchar('X'); */
X
X for(i = 0; i < BUFSIZ; i++)
X buffer[i] = 'X';
X
X while ( numchrs > 0L) {
X write(1, buffer, (numchrs > BUFSIZ ? BUFSIZ : numchrs));
X numchrs -= BUFSIZ;
X }
X}
SHAR_EOF
if test 595 -ne "`wc -c < 'mysend.c'`"
then
echo shar: "error transmitting 'mysend.c'" '(should have been 595 characters)'
fi
fi
echo shar: "extracting 'mytest.sh'" '(482 characters)'
if test -f 'mytest.sh'
then
echo shar: "will not over-write existing file 'mytest.sh'"
else
sed 's/^ X//' << \SHAR_EOF > 'mytest.sh'
Xecho "\nmysend <n> | myrecv\n"
X./mysend 100000 | ./myrecv
X./mysend 200000 | ./myrecv
X./mysend 300000 | ./myrecv
X./mysend 400000 | ./myrecv
X./mysend 500000 | ./myrecv
X./mysend 1000000 | ./myrecv
Xecho "\nmysend <n> | dd bs=5k | myrecv\n"
X./mysend 100000 | dd bs=5k | ./myrecv
X./mysend 200000 | dd bs=5k | ./myrecv
X./mysend 300000 | dd bs=5k | ./myrecv
X./mysend 400000 | dd bs=5k | ./myrecv
X./mysend 500000 | dd bs=5k | ./myrecv
X./mysend 1000000 | dd bs=5k | ./myrecv
SHAR_EOF
if test 482 -ne "`wc -c < 'mytest.sh'`"
then
echo shar: "error transmitting 'mytest.sh'" '(should have been 482 characters)'
fi
chmod +x 'mytest.sh'
fi
echo shar: "extracting 'pass.c'" '(247 characters)'
if test -f 'pass.c'
then
echo shar: "will not over-write existing file 'pass.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'pass.c'
X/* pass.c
X *
X * just passes/handoffs chars from stdin to stdout until EOF for testing
X * the speed of pipes on the system.
X *
X * Thad Floryan, 26-Nov-1990
X */
X
X#include <stdio.h>
X
Xmain()
X{
X int c;
X
X while ( (c = getchar()) != EOF ) putchar(c);
X
X}
SHAR_EOF
if test 247 -ne "`wc -c < 'pass.c'`"
then
echo shar: "error transmitting 'pass.c'" '(should have been 247 characters)'
fi
fi
echo shar: "extracting 'recv.c'" '(824 characters)'
if test -f 'recv.c'
then
echo shar: "will not over-write existing file 'recv.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'recv.c'
X/* recv.c
X *
X * just receives chars from stdin until EOF for testing the speed
X * of pipes on the system.
X *
X * Thad Floryan, 26-Nov-1990
X */
X
X#include <stdio.h>
X#include <sys/param.h> /* for def of HZ */
X#include <sys/types.h>
X#include <sys/times.h>
X
Xmain()
X{
X extern long times();
X
X long startime, endtime, elapsed;
X struct tms timebuf;
X long numchrs = 0;
X
X startime = times(&timebuf); /* get start time in HZ units */
X
X while ( getchar() != EOF ) ++numchrs;
X
X endtime = times(&timebuf); /* get completion time in HZ units */
X
X if ( (elapsed = endtime - startime) != 0L )
X {
X printf("%d characters received in %d.%03d seconds for %d CPS\n",
X numchrs,
X elapsed / HZ,
X ((elapsed % HZ) * 1000L) / HZ,
X ((numchrs * HZ) / elapsed ));
X }
X else
X {
X printf("Insufficient timer resolution for supplied input\n");
X }
X}
SHAR_EOF
if test 824 -ne "`wc -c < 'recv.c'`"
then
echo shar: "error transmitting 'recv.c'" '(should have been 824 characters)'
fi
fi
echo shar: "extracting 'send.c'" '(332 characters)'
if test -f 'send.c'
then
echo shar: "will not over-write existing file 'send.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'send.c'
X/* send.c
X *
X * just sends argv[1] number of characters out for testing the speed
X * of pipes on the system.
X *
X * Thad Floryan, 26-Nov-1990
X */
X
X#include <stdio.h>
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X long numchrs;
X
X numchrs = atol(argv[1]); /* dismiss error checks for now */
X
X while ( --numchrs >= 0L ) putchar('X');
X}
SHAR_EOF
if test 332 -ne "`wc -c < 'send.c'`"
then
echo shar: "error transmitting 'send.c'" '(should have been 332 characters)'
fi
fi
echo shar: "extracting 'test.sh'" '(411 characters)'
if test -f 'test.sh'
then
echo shar: "will not over-write existing file 'test.sh'"
else
sed 's/^ X//' << \SHAR_EOF > 'test.sh'
Xecho "\nsend <n> | recv\n"
X./send 100000 | ./recv
X./send 200000 | ./recv
X./send 300000 | ./recv
X./send 400000 | ./recv
X./send 500000 | ./recv
X./send 1000000 | ./recv
Xecho "\nsend <n> | pass | recv\n"
X./send 100000 | ./pass | ./recv
X./send 200000 | ./pass | ./recv
X./send 300000 | ./pass | ./recv
X./send 400000 | ./pass | ./recv
X./send 500000 | ./pass | ./recv
X./send 1000000 | ./pass | ./recv
SHAR_EOF
if test 411 -ne "`wc -c < 'test.sh'`"
then
echo shar: "error transmitting 'test.sh'" '(should have been 411 characters)'
fi
chmod +x 'test.sh'
fi
exit 0
# End of shell archive
--
Rob Stampfli / att.com!stampfli (uucp at work) / kd8wk at w8cqk (packet radio)
614-864-9377 / osu-cis.cis.ohio-state.edu!kd8wk!res (uucp at home)
More information about the Comp.sys.att
mailing list