timer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * ECOS - Embedded Conic Solver.
  3. * Copyright (C) 2012-2015 A. Domahidi [domahidi@embotech.com],
  4. * Automatic Control Lab, ETH Zurich & embotech GmbH, Zurich, Switzerland.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * Interface for the built-in timer of ECOS.
  21. */
  22. #ifndef __TIMER_H__
  23. #define __TIMER_H__
  24. #include "glblopts.h"
  25. #if PROFILING > 0
  26. #if (defined _WIN32 || defined _WIN64 || defined _WINDLL )
  27. /* Use Windows QueryPerformanceCounter for timing */
  28. #include <windows.h>
  29. typedef struct timer{
  30. __int64 tic;
  31. __int64 toc;
  32. __int64 freq;
  33. } timer;
  34. #elif (defined __APPLE__)
  35. #include <mach/mach_time.h>
  36. /* Use MAC OSX mach_time for timing */
  37. typedef struct timer{
  38. uint64_t tic;
  39. uint64_t toc;
  40. mach_timebase_info_data_t tinfo;
  41. } timer;
  42. #else
  43. /* Use POSIX clocl_gettime() for timing on non-Windows machines */
  44. #include <time.h>
  45. #include <sys/time.h>
  46. typedef struct timer{
  47. struct timespec tic;
  48. struct timespec toc;
  49. } timer;
  50. #endif
  51. /* METHODS are the same for both */
  52. void tic(timer* t);
  53. pfloat toc(timer* t);
  54. #endif /* END IF PROFILING > 0 */
  55. #endif
  56. /* END IFDEF __TIMER_H__ */