Beispiel #1
0
/*******************************************************************//**
Shows the time elapsed and usage statistics since the last reset of a
speedo. */
UNIV_INTERN
void
speedo_show(
/*========*/
	const speedo_t*	speedo)	/*!< in: speedo */
{
	struct rusage	ru_now;
	struct timeval	tv_now;
	struct timeval	tv_diff;

	getrusage(RUSAGE_SELF, &ru_now);

	gettimeofday(&tv_now, NULL);

#define PRINT_TIMEVAL(prefix, tvp)		\
	fprintf(stderr, "%s% 5ld.%06ld sec\n",	\
		prefix, (tvp)->tv_sec, (tvp)->tv_usec)

	timersub(&tv_now, &speedo->tv, &tv_diff);
	PRINT_TIMEVAL("real", &tv_diff);

	timersub(&ru_now.ru_utime, &speedo->ru.ru_utime, &tv_diff);
	PRINT_TIMEVAL("user", &tv_diff);

	timersub(&ru_now.ru_stime, &speedo->ru.ru_stime, &tv_diff);
	PRINT_TIMEVAL("sys ", &tv_diff);
}
Beispiel #2
0
int main(int argc, char *argv[]) {

  if (argc != 3) {
    printf("%s <num rands> <num threads>\n", argv[0]);
    exit(1);
  }

  uint64_t i, j, num_rands = atoi(argv[1]);
  uint64_t num_threads     = atoi(argv[2]);

  srand(time(NULL));


  TClient *clients  = malloc(sizeof(TClient)   * num_threads);
  ThreadArgs **args = malloc(sizeof(ThreadArgs *) * num_threads);

  for (i = 0; i < num_threads; i++) {
    init_thread_client(&clients[i]);

    args[i] = malloc(sizeof(ThreadArgs));
    args[i]->i = i;
    args[i]->num_threads = num_threads;
    args[i]->num_rands   = num_rands;
  }

  
  struct timeval rand32_r, rand128_r, normal_r;// result
  struct timeval rand32_s, rand128_s, normal_s;// start
  struct timeval rand32_e, rand128_e, normal_e;// end


  gettimeofday(&rand32_s, NULL);
  for (j = 0; j < num_threads; j++)
    tc_add_func(&clients[j], rand32_new, (void *) args[j]);
  
  for (j = 0; j < num_threads; j++) 
    tc_join(&clients[j]);

  gettimeofday(&rand32_e, NULL);
  timeval_subtract(&rand32_r, &rand32_e, &rand32_s);

  gettimeofday(&rand128_s, NULL);
  for (j = 0; j < num_threads; j++)
    tc_add_func(&clients[j], rand128_new, (void *) args[j]);
  
  for (j = 0; j < num_threads; j++) 
    tc_join(&clients[j]);

  gettimeofday(&rand128_e, NULL);
  timeval_subtract(&rand128_r, &rand128_e, &rand128_s);

  gettimeofday(&normal_s, NULL);
  for (j = 0; j < num_threads; j++)
    tc_add_func(&clients[j], normal_rand, (void *) args[j]);
  
  for (j = 0; j < num_threads; j++) 
    tc_join(&clients[j]);
  
  gettimeofday(&normal_e, NULL);
  timeval_subtract(&normal_r, &normal_e, &normal_s);

  printf("rand32:  ");
  PRINT_TIMEVAL(rand32_r);
  printf("\n");
  
  printf("rand128: ");
  PRINT_TIMEVAL(rand128_r);
  printf("\n");

  printf("normal:  ");
  PRINT_TIMEVAL(normal_r);
  printf("\n");

  for (i = 0; i < num_threads; i++) {
    tc_free(&clients[i]);
    free(args[i]);
  }

  free(args);
  free(clients);

  return 0;
}