timer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // LUOYC
  46. //#include <sys/time.h>
  47. struct timespec
  48. {
  49. int tv_sec; /* Seconds. */
  50. int tv_nsec; /* Nanoseconds. */
  51. };
  52. typedef struct timer{
  53. struct timespec tic;
  54. struct timespec toc;
  55. } timer;
  56. #endif
  57. /* METHODS are the same for both */
  58. void tic(timer* t);
  59. pfloat toc(timer* t);
  60. #endif /* END IF PROFILING > 0 */
  61. #endif
  62. /* END IFDEF __TIMER_H__ */