benchmark.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Gearman server and library
  2. * Copyright (C) 2008 Brian Aker, Eric Day
  3. * All rights reserved.
  4. *
  5. * Use and distribution licensed under the BSD license. See
  6. * the COPYING file in the parent directory for full text.
  7. */
  8. /**
  9. * @file
  10. * @brief Common benchmark functions
  11. */
  12. #include <benchmark/benchmark.h>
  13. #include <stdio.h>
  14. /*
  15. * Public definitions
  16. */
  17. void benchmark_init(gearman_benchmark_st *benchmark)
  18. {
  19. memset(benchmark, 0, sizeof(gearman_benchmark_st));
  20. gettimeofday(&(benchmark->total), NULL);
  21. gettimeofday(&(benchmark->begin), NULL);
  22. }
  23. void benchmark_check_time(gearman_benchmark_st *benchmark)
  24. {
  25. benchmark->jobs++;
  26. gettimeofday(&(benchmark->end), NULL);
  27. if (benchmark->end.tv_sec != benchmark->begin.tv_sec)
  28. {
  29. benchmark->total_jobs+= benchmark->jobs;
  30. printf("[Current: %6"PRIu64" jobs/s, Total: %6"PRIu64" jobs/s]\n",
  31. ((uint64_t)(benchmark->jobs) * 1000000) /
  32. ((((uint64_t)(benchmark->end.tv_sec) * 1000000) +
  33. (uint64_t)(benchmark->end.tv_usec)) -
  34. (((uint64_t)(benchmark->begin.tv_sec) * 1000000) +
  35. (uint64_t)(benchmark->begin.tv_usec))),
  36. ((uint64_t)(benchmark->total_jobs) * 1000000) /
  37. ((((uint64_t)(benchmark->end.tv_sec) * 1000000) +
  38. (uint64_t)(benchmark->end.tv_usec)) -
  39. (((uint64_t)(benchmark->total.tv_sec) * 1000000) +
  40. (uint64_t)(benchmark->total.tv_usec))));
  41. benchmark->jobs= 0;
  42. gettimeofday(&(benchmark->begin), NULL);
  43. }
  44. }