Lecture Notes for Client-Server Interfaces

15 March 2001 - Process vs Threads Performance


How Much Do Each Cost?


The Contenders


The details

#define iters 2000

static void * f(void *) {
  return NULL;
  }

int main(int argc, char * argv[]) {

  int i;
  time_t s, oh;

  timeit(oh,);
  printf("%d usec loop overhead for %d iterations, %g usec/iter.\n",
	 oh, iters, ((double) oh)/((double) iters));

  // fork timing code

  printf("%g usec per fork() call for %d calls.\n", 
	 ((double) (s - oh))/((double) iters), iters);


  // thread timing code

  printf("%g usec per pthread_create() call for %d calls.\n",
	 ((double) (s - oh))/((double) iters),  iters);


  return EXIT_SUCCESS;
  }


The Results

cl date
Thu Mar 15 14:42:55 EST 2001

cl uname -a
SunOS clayton 5.7 Generic_106541-11 sun4u sparc SUNW,Ultra-5_10

cl g++ -o forktime forktime.cc -lpthread

cl forktime
Loop overhead is 79 usec for 2000 iterations, 0.0395 usec/iteration.
Time per fork() call for 2000 calls: 7817.5 usec.
Time per pthread_create() call for 2000 calls: 104.193 usec.

cl forktime
Loop overhead is 79 usec for 2000 iterations, 0.0395 usec/iteration.
Time per fork() call for 2000 calls: 7864.8 usec.
Time per pthread_create() call for 2000 calls: 109.993 usec.

cl CC -o forktime forktime.cc -lpthread

cl forktime
Loop overhead is 19 usec for 2000 iterations, 0.0095 usec/iteration.
Time per fork() call for 2000 calls: 7803.37 usec.
Time per pthread_create() call for 2000 calls: 82.0435 usec.

cl forktime
Loop overhead is 19 usec for 2000 iterations, 0.0095 usec/iteration.
Time per fork() call for 2000 calls: 7825.22 usec.
Time per pthread_create() call for 2000 calls: 103.33 usec.

cl 


Other Systems


Conclusions


This page last modified on 10 April 2001.