Questions tagged [gettimeofday]

The function gettimeofday() can get the time as well as a timezone.

Read more in the Linux Reference.

100 questions
4
votes
2 answers

strange timing results for 'clock_gettime' and 'gettimeofday'

I wanted to check the reliability of clock_gettime, using the deprecated gettimeofday as reference, but am getting strange results sometimes: #include #include #include void clock_gettime_test() { struct…
tshepang
  • 12,111
  • 21
  • 91
  • 136
3
votes
2 answers

Slow initial timing results using gettimeofday - worse under RHEL6 Server

I am using gettimeofday() to time a simple matrix multiply example, but I'm getting results that are close to twice too long initially. On a RHEL6 Server machine, I'm getting "bad" timing results for up to nearly 1 second (~65 individual timings in…
chrisG
  • 65
  • 4
3
votes
2 answers

How to subtract two gettimeofday instances?

I want to subtract two gettimeofday instances, and present the answer in milliseconds. The idea is: static struct timeval tv; gettimeofday(&tv, NULL); static struct timeval tv2; gettimeofday(&tv2, NULL); static struct timeval…
user1106106
  • 277
  • 2
  • 7
  • 13
3
votes
5 answers

unable to link to gettimeofday on embedded system, elapsed time suggestions?

I am trying to use gettimeofday on an embedded ARM device, however it seems as though I am unable to use it: gnychis@ubuntu:~/Documents/coexisyst/econotag_firmware$ make Building for board: redbee-econotag CC…
gnychis
  • 7,289
  • 18
  • 75
  • 113
3
votes
2 answers

error when passing pointer to struct to function in c

I'm trying to pass pointers to two struct timevals to a function that would output the elapsed time between the two in a C program. However, even if I dereference these pointers, nvcc throws the error "expression must have class type" (this is a…
Andrew
  • 1,081
  • 1
  • 8
  • 19
3
votes
1 answer

python time.time() differences in python 2 vs 3

I am wondering why python 2.7 uses gettimeofday() when running time.time() but yet in python 3.4 it does not? It appears when running strace that it may be querying /etc/localtime
3
votes
2 answers

what is gettimeofday() equivalent in c++11

Probably duplicate, but What is gettimeofday() equivalent in c++11 ? I am trying to get 64 bit timestamp with microseconds, similar to Java / Python.
Nick
  • 9,962
  • 4
  • 42
  • 80
3
votes
1 answer

Swift: gettimeofday and Unsafe Pointers

The code in Swift ... var time:timeval? gettimeofday(UnsafePointer, UnsafePointer<()>) // this is the method expansion before filling in any data ... The code in Objective C ... struct timeval time; gettimeofday(&time, NULL); ... I have…
solenoid
  • 954
  • 1
  • 9
  • 20
3
votes
2 answers

Time from gettimeofday not updating as it should

#include #include int main() { float time; struct timeval tv; gettimeofday( &tv, NULL ); time = tv.tv_sec + ( tv.tv_usec / 1000000.0 ); printf( "time: %f\n", time ); return 0; } Running binary generated by…
tshepang
  • 12,111
  • 21
  • 91
  • 136
3
votes
3 answers

gettimeofday returns a negative value

I am writing a thread library, and when scheduling the threads I need to know how long they've been ready. Every Thread instance has a timeval _timeInReady field, and when I push an instance to the ready queue I call this function: void…
yotamoo
  • 5,334
  • 13
  • 49
  • 61
2
votes
1 answer

Why is my syscall error check in assembly failing to work?

I wrote a snippet of x86-64 to get current time of day on a mac using a syscall. Everything worked fine. I got a time. Then I thought to add a little error checking. To get an idea of what to do, I disassembled the "gettimeofday" wrapper. It…
Chris
  • 342
  • 1
  • 12
2
votes
1 answer

Is there a safe way to call gettimeofday() from a Xenomai real time thread?

I'm running a Xenomai real time thread that sometimes needs to call gettimeofday(), in order to find out what the current time is according to ptpd. However, doing that appears to be unsafe: in particular, it occasionally puts the Xenomai thread…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
2
votes
3 answers

gettimeofday() - Why use both seconds and microseconds?

I need to use the function gettimeofday for a home assignment, and after reading the man page and looking some online examples, I can't see why people sometimes use both the tv_sec member of the struct and tv_usec member of the struct. The man page…
Tegernako
  • 289
  • 1
  • 9
2
votes
3 answers

gettimeofday() microsecond not limited to below second

When I output the microseconds field for gettimeofday(), I notice that the microsecond field is larger than 1,000,000. Does anyone know why this is? And does this imply that I've been interpreting gettimeofday() wrong? For the record, my assumption…
Daniel Handojo
  • 612
  • 5
  • 19
2
votes
1 answer

Seconds calculation using rdtsc

Here is the code to calculate CPU time but it's not correct because when I use gettimeofday it gives me correct time in ms. I am running my process on one processor and its clock runs at 800MHz. My knowledge about rdtsc is as follows: Rdtsc returns…
Anonymous
  • 93
  • 2
  • 9