std-unix@ut-sally.UUCP (Moderator, John Quarterman) (12/10/85)
From: harvard!wjh12!panda!teddy!jpn (John P. Nelson) Date: Mon, 9 Dec 85 11:35:09 est >I decided to do a little testing to see how much the size of my >environment affected response time. > I suspected that the iteration time was affected by the shell searching the environment, rather than an increase in fork/exec time. I wrote a C program to do the same thing as the shell script written by John P. Linderman. I was wrong! The following results were achieved on a diskless SUN-2 workstation (a "perfmeter" running along side indicated 100% cpu usage, and 0% ethernet activity - apparently everything remained in memory) I would have used a VAX, but didn't want to annoy my fellow employees). Your numbers will vary: % testit Env size 56, loop time 135 Env size 113, loop time 139 Env size 227, loop time 158 Env size 455, loop time 167 Env size 911, loop time 207 Env size 1823, loop time 292 Env size 3647, loop time 470 Env size 7295, loop time 846 fork or exec failure: terminating John P. Nelson (decvax!genrad!teddy!jpn seismo!harvard!talcott!panda!teddy!jpn) --- cut here. testit.c follows: --- #include <stdio.h> char *env[2]; char *echoargv[] = { "echo", "abc", (char *) 0 }; #define DEFAULTENV "TEST=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" #define INNERLOOP 1000 main() { extern char *malloc(), *realloc(); register int i; register char *ptr; long starttime; long endtime; int waitst; env[0] = malloc(sizeof(DEFAULTENV)); strcpy(env[0], DEFAULTENV); env[1] = 0; close(1); /* close up stdout */ if (open("/dev/null", 2) < 0) { fprintf(stderr, "Can't open /dev/null on 1\n"); } while (1) /* or until failure */ { time(&starttime); for (i = 0; i < INNERLOOP; ++i) { /* do the fork/exec */ if (fork() == 0) { execve("/bin/echo", echoargv, env); exit(-1); /* exec failure */ } /* terminate on anything but successfull exit(0) */ if (wait(&waitst) < 0 || (waitst & 0xFFFF) != 0) { fprintf(stderr, "fork or exec failure: terminating\n"); exit(0); } } time(&endtime); fprintf(stderr, "Env size %d, loop time %ld\n", strlen(env[0]), endtime - starttime); /* now double the environment size */ env[0] = realloc(env[0], (strlen(env[0])+1) * 2); ptr = env[0] + strlen(env[0]); /* point to trailing null */ strcpy(ptr+1, env[0]); /* tack on another copy */ *ptr = '\n'; /* and join the two strings */ } /* NOTREACHED */ } Volume-Number: Volume 4, Number 7