Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include "util.h"
- int main() {
- int i;
- uint64_t cycles[10];
- for (i = 0; i < 10; ++i) {
- // get initial cycles
- uint64_t init = GetRDTSC();
- gettimeofday(); // <== time(0) will work here without a seg fault.
- // get cycles after
- uint64_t after = GetRDTSC();
- // save cycles for each operation in an array
- cycles[i] = after - init;
- printf("%in", (int)(cycles[i]));
- }
- }
- #include <sys/time.h>
- #include <stdio.h>
- int main() {
- struct timeval tv;
- gettimeofday(&tv, NULL); // timezone should be NULL
- printf("%d secondsn", tv.tv_secs);
- return 0;
- }
- int main() {
- gettimeofday();
- return 0;
- }
- ternus@event-horizon ~> gcc -o foo foo.c
- ternus@event-horizon ~> ldd foo
- linux-vdso.so.1 => (0x00007ffff33fe000)
- libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f56a5255000)
- /lib64/ld-linux-x86-64.so.2 (0x00007f56a562b000)
- ternus@event-horizon ~> gcc -Wall -o foo foo.c
- foo.c: In function ‘main’:
- foo.c:2:3: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
- cternus@astarael ~/foo> gcc -o foo -g foo.c
- cternus@astarael ~/foo> gdb foo
- GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012)
- [etc]
- (gdb) run
- Starting program: /Users/cternus/foo/foo
- Reading symbols for shared libraries +.............................. done
- Program received signal EXC_BAD_ACCESS, Could not access memory.
- Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001
- 0x00007fff87eeab73 in __commpage_gettimeofday ()
- typedef struct {
- long tv_sec;
- long tv_usec;
- } timeval;
- int main() {
- timeval tv;
- gettimeofday(&tv, 0);
- return 0;
- }
- #include <sys/time.h>
Add Comment
Please, Sign In to add comment