Guest User

Untitled

a guest
Apr 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include "util.h"
  4.  
  5. int main() {
  6.  
  7. int i;
  8. uint64_t cycles[10];
  9.  
  10. for (i = 0; i < 10; ++i) {
  11.  
  12. // get initial cycles
  13. uint64_t init = GetRDTSC();
  14.  
  15. gettimeofday(); // <== time(0) will work here without a seg fault.
  16.  
  17. // get cycles after
  18. uint64_t after = GetRDTSC();
  19.  
  20. // save cycles for each operation in an array
  21. cycles[i] = after - init;
  22.  
  23. printf("%in", (int)(cycles[i]));
  24. }
  25. }
  26.  
  27. #include <sys/time.h>
  28. #include <stdio.h>
  29. int main() {
  30. struct timeval tv;
  31. gettimeofday(&tv, NULL); // timezone should be NULL
  32. printf("%d secondsn", tv.tv_secs);
  33. return 0;
  34. }
  35.  
  36. int main() {
  37. gettimeofday();
  38. return 0;
  39. }
  40.  
  41. ternus@event-horizon ~> gcc -o foo foo.c
  42. ternus@event-horizon ~> ldd foo
  43. linux-vdso.so.1 => (0x00007ffff33fe000)
  44. libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f56a5255000)
  45. /lib64/ld-linux-x86-64.so.2 (0x00007f56a562b000)
  46.  
  47. ternus@event-horizon ~> gcc -Wall -o foo foo.c
  48. foo.c: In function ‘main’:
  49. foo.c:2:3: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
  50.  
  51. cternus@astarael ~/foo> gcc -o foo -g foo.c
  52. cternus@astarael ~/foo> gdb foo
  53. GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012)
  54. [etc]
  55.  
  56. (gdb) run
  57. Starting program: /Users/cternus/foo/foo
  58. Reading symbols for shared libraries +.............................. done
  59.  
  60. Program received signal EXC_BAD_ACCESS, Could not access memory.
  61. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001
  62. 0x00007fff87eeab73 in __commpage_gettimeofday ()
  63.  
  64. typedef struct {
  65. long tv_sec;
  66. long tv_usec;
  67. } timeval;
  68.  
  69. int main() {
  70. timeval tv;
  71. gettimeofday(&tv, 0);
  72. return 0;
  73. }
  74.  
  75. #include <sys/time.h>
Add Comment
Please, Sign In to add comment