You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

bench.h 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #ifdef __CYGWIN32__
  5. #include <sys/time.h>
  6. #endif
  7. #include "common.h"
  8. #if defined(__WIN32__) || defined(__WIN64__)
  9. #ifndef DELTA_EPOCH_IN_MICROSECS
  10. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  11. #endif
  12. int gettimeofday(struct timeval *tv, void *tz){
  13. FILETIME ft;
  14. unsigned __int64 tmpres = 0;
  15. static int tzflag;
  16. if (NULL != tv)
  17. {
  18. GetSystemTimeAsFileTime(&ft);
  19. tmpres |= ft.dwHighDateTime;
  20. tmpres <<= 32;
  21. tmpres |= ft.dwLowDateTime;
  22. /*converting file time to unix epoch*/
  23. tmpres /= 10; /*convert into microseconds*/
  24. tmpres -= DELTA_EPOCH_IN_MICROSECS;
  25. tv->tv_sec = (long)(tmpres / 1000000UL);
  26. tv->tv_usec = (long)(tmpres % 1000000UL);
  27. }
  28. return 0;
  29. }
  30. #endif
  31. #if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
  32. static void *huge_malloc(BLASLONG size){
  33. int shmid;
  34. void *address;
  35. #ifndef SHM_HUGETLB
  36. #define SHM_HUGETLB 04000
  37. #endif
  38. if ((shmid =shmget(IPC_PRIVATE,
  39. (size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
  40. SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
  41. printf( "Memory allocation failed(shmget).\n");
  42. exit(1);
  43. }
  44. address = shmat(shmid, NULL, SHM_RND);
  45. if ((BLASLONG)address == -1){
  46. printf( "Memory allocation failed(shmat).\n");
  47. exit(1);
  48. }
  49. shmctl(shmid, IPC_RMID, 0);
  50. return address;
  51. }
  52. #define malloc huge_malloc
  53. #endif
  54. #if defined(__WIN32__) || defined(__WIN64__) || !defined(_POSIX_TIMERS)
  55. struct timeval start, stop;
  56. #else
  57. struct timespec start = { 0, 0 }, stop = { 0, 0 };
  58. #endif
  59. double getsec()
  60. {
  61. #if defined(__WIN32__) || defined(__WIN64__) || !defined(_POSIX_TIMERS)
  62. return (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
  63. #else
  64. return (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_nsec - start.tv_nsec)) * 1.e-9;
  65. #endif
  66. }
  67. void begin() {
  68. #if defined(__WIN32__) || defined(__WIN64__) || !defined(_POSIX_TIMERS)
  69. gettimeofday( &start, (struct timezone *)0);
  70. #else
  71. clock_gettime(CLOCK_REALTIME, &start);
  72. #endif
  73. }
  74. void end() {
  75. #if defined(__WIN32__) || defined(__WIN64__) || !defined(_POSIX_TIMERS)
  76. gettimeofday( &stop, (struct timezone *)0);
  77. #else
  78. clock_gettime(CLOCK_REALTIME, &stop);
  79. #endif
  80. }