Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bench.h 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2011-2014 David Robillard <http://drobilla.net>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. /**
  15. @file bench.h A simple real-time benchmarking API.
  16. */
  17. #ifndef BENCH_H
  18. #define BENCH_H
  19. #define _POSIX_C_SOURCE 199309L
  20. #include <time.h>
  21. #include <sys/time.h>
  22. static inline double
  23. bench_elapsed_s(const struct timespec* start, const struct timespec* end)
  24. {
  25. return ((end->tv_sec - start->tv_sec)
  26. + ((end->tv_nsec - start->tv_nsec) * 0.000000001));
  27. }
  28. static inline struct timespec
  29. bench_start(void)
  30. {
  31. struct timespec start_t;
  32. clock_gettime(CLOCK_REALTIME, &start_t);
  33. return start_t;
  34. }
  35. static inline double
  36. bench_end(const struct timespec* start_t)
  37. {
  38. struct timespec end_t;
  39. clock_gettime(CLOCK_REALTIME, &end_t);
  40. return bench_elapsed_s(start_t, &end_t);
  41. }
  42. #endif /* BENCH_H */