benchmark.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 <config.h>
  13. #include <benchmark/benchmark.h>
  14. #include <cstdio>
  15. /*
  16. * Public definitions
  17. */
  18. void benchmark_check_time(gearman_benchmark_st *benchmark)
  19. {
  20. benchmark->jobs++;
  21. gettimeofday(&(benchmark->end), NULL);
  22. if (benchmark->end.tv_sec != benchmark->begin.tv_sec)
  23. {
  24. benchmark->total_jobs+= benchmark->jobs;
  25. printf("[Current: %6"PRIu64" jobs/s, Total: %6"PRIu64" jobs/s]\n",
  26. (uint64_t(benchmark->jobs) * 1000000) /
  27. (((uint64_t(benchmark->end.tv_sec) * 1000000) +
  28. uint64_t(benchmark->end.tv_usec)) -
  29. ((uint64_t(benchmark->begin.tv_sec) * 1000000) +
  30. uint64_t(benchmark->begin.tv_usec))),
  31. (uint64_t(benchmark->total_jobs) * 1000000) /
  32. (((uint64_t(benchmark->end.tv_sec) * 1000000) +
  33. uint64_t(benchmark->end.tv_usec)) -
  34. ((uint64_t(benchmark->total.tv_sec) * 1000000) +
  35. uint64_t(benchmark->total.tv_usec))));
  36. benchmark->jobs= 0;
  37. gettimeofday(&(benchmark->begin), NULL);
  38. }
  39. }