home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / mod.std.unix.v4 / text0006.txt < prev    next >
Encoding:
Internet Message Format  |  1987-06-30  |  2.5 KB

  1. From: harvard!wjh12!panda!teddy!jpn (John P. Nelson)
  2. Date: Mon, 9 Dec 85 11:35:09 est
  3.  
  4. >I decided to do a little testing to see how much the size of my
  5. >environment affected response time.
  6. >
  7.  
  8. I suspected that the iteration time was affected by the shell searching the
  9. environment, rather than an increase in fork/exec time.  I wrote a C program
  10. to do the same thing as the shell script written by John P. Linderman.  I
  11. was wrong!
  12.  
  13. The following results were achieved on a diskless SUN-2 workstation (a
  14. "perfmeter" running along side indicated 100% cpu usage, and 0% ethernet
  15. activity - apparently everything remained in memory) I would have used a VAX,
  16. but didn't want to annoy my fellow employees).  Your numbers will vary:
  17.  
  18. % testit
  19. Env size 56, loop time 135
  20. Env size 113, loop time 139
  21. Env size 227, loop time 158
  22. Env size 455, loop time 167
  23. Env size 911, loop time 207
  24. Env size 1823, loop time 292
  25. Env size 3647, loop time 470
  26. Env size 7295, loop time 846
  27. fork or exec failure: terminating
  28.  
  29.  
  30. John P. Nelson (decvax!genrad!teddy!jpn seismo!harvard!talcott!panda!teddy!jpn)
  31.  
  32. --- cut here.  testit.c follows: ---
  33. #include <stdio.h>
  34.  
  35. char *env[2];
  36. char *echoargv[] =
  37.     {
  38.     "echo",
  39.     "abc",
  40.     (char *) 0
  41.     };
  42.  
  43. #define DEFAULTENV "TEST=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  44. #define INNERLOOP 1000
  45.  
  46. main()
  47.     {
  48.     extern char *malloc(), *realloc();
  49.     register int i;
  50.     register char *ptr;
  51.     long starttime;
  52.     long endtime;
  53.     int waitst;
  54.  
  55.     env[0] = malloc(sizeof(DEFAULTENV));
  56.     strcpy(env[0], DEFAULTENV);
  57.     env[1] = 0;
  58.     close(1);            /* close up stdout */
  59.     if (open("/dev/null", 2) < 0)
  60.     {
  61.     fprintf(stderr, "Can't open /dev/null on 1\n");
  62.     }
  63.  
  64.     while (1)    /* or until failure */
  65.     {
  66.     time(&starttime);
  67.     for (i = 0; i < INNERLOOP; ++i)
  68.         {
  69.         /* do the fork/exec */
  70.         if (fork() == 0)
  71.         {
  72.         execve("/bin/echo", echoargv, env);
  73.         exit(-1);        /* exec failure */
  74.         }
  75.  
  76.         /* terminate on anything but successfull exit(0) */
  77.         if (wait(&waitst) < 0 || (waitst & 0xFFFF) != 0)
  78.         {
  79.         fprintf(stderr, "fork or exec failure: terminating\n");
  80.         exit(0);
  81.         }
  82.         }
  83.     time(&endtime);
  84.     fprintf(stderr, "Env size %d, loop time %ld\n",
  85.         strlen(env[0]), endtime - starttime);
  86.     /* now double the environment size */
  87.     env[0] = realloc(env[0], (strlen(env[0])+1) * 2);
  88.     ptr = env[0] + strlen(env[0]);        /* point to trailing null */
  89.     strcpy(ptr+1, env[0]);            /* tack on another copy */
  90.     *ptr = '\n';                /* and join the two strings */
  91.     }
  92.     /* NOTREACHED */
  93.     }
  94.  
  95. Volume-Number: Volume 4, Number 7
  96.  
  97.