benchmark.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_check_time(gearman_benchmark_st *benchmark)
  18. {
  19. benchmark->jobs++;
  20. gettimeofday(&(benchmark->end), NULL);
  21. if (benchmark->end.tv_sec != benchmark->begin.tv_sec)
  22. {
  23. benchmark->total_jobs+= benchmark->jobs;
  24. printf("[Current: %6"PRIu64" jobs/s, Total: %6"PRIu64" jobs/s]\n",
  25. (uint64_t(benchmark->jobs) * 1000000) /
  26. (((uint64_t(benchmark->end.tv_sec) * 1000000) +
  27. uint64_t(benchmark->end.tv_usec)) -
  28. ((uint64_t(benchmark->begin.tv_sec) * 1000000) +
  29. uint64_t(benchmark->begin.tv_usec))),
  30. (uint64_t(benchmark->total_jobs) * 1000000) /
  31. (((uint64_t(benchmark->end.tv_sec) * 1000000) +
  32. uint64_t(benchmark->end.tv_usec)) -
  33. ((uint64_t(benchmark->total.tv_sec) * 1000000) +
  34. uint64_t(benchmark->total.tv_usec))));
  35. benchmark->jobs= 0;
  36. gettimeofday(&(benchmark->begin), NULL);
  37. }
  38. }