Questions tagged [gettimeofday]

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

Read more in the Linux Reference.

100 questions
30
votes
5 answers

faster equivalent of gettimeofday

In trying to build a very latency sensitive application, that needs to send 100s of messages a seconds, each message having the time field, we wanted to consider optimizing gettimeofday. Out first thought was rdtsc based optimization. Any thoughts…
Humble Debugger
  • 4,439
  • 11
  • 39
  • 56
21
votes
3 answers

time() and gettimeofday() return different seconds

On the two systems I've tested (a 32-bit Ubuntu 12.04 server and a 64-bit Ubuntu 13.10 VM), the seconds since the epoch given by time() may differ from gettimeofday()'s. Specifically, though I call time() after calling gettimeofday(), the value…
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
21
votes
4 answers

What should I use to replace gettimeofday() on Windows?

I'm writing a portable Socket class that supports timeouts for both sending and receiving... To implement these timeouts I'm using select().... But, I sometimes need to know how long I was blocked inside select() which of course on Linux I would…
dicroce
  • 45,396
  • 28
  • 101
  • 140
11
votes
4 answers

how to use gettimeofday() or something equivalent with Visual Studio C++ 2008?

Could someone please help me to use gettimeofday() function with Visual Studio C++ 2008 on Windows XP? here is a code that I found somewhere on the net: #include < time.h > #include #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) …
make
  • 755
  • 7
  • 21
  • 37
7
votes
2 answers

millisecond-accurate benchmarking in C++?

I do not really wish to profile because I was wanting to do many different small benchmarks on different simple functions. For the life of me I cannot find a way to record the amount of milliseconds in C++, I am using Linux by the way. Can you…
John
  • 1,110
  • 3
  • 14
  • 28
6
votes
2 answers

gettimeofday() always accessible?

I've tried Google, php.net and the php mailinglist's archives, but I can't find what I'm looking for. Maybe it's obvious, or maybe nobody wonders about this... For years, I've used microtime() to get the current time including the microseconds.…
lugte098
  • 2,271
  • 5
  • 21
  • 30
6
votes
2 answers

In what cases CLOCK_MONOTONIC might not be available

In Java System.nanoTime()'s monotonic implementation on Linux relies on the fact that CLOCK_MONOTONIC is available on the OS. If it's not available, it falls back to gettimeofday which can result in getting a negative time interval when the interval…
SerCe
  • 5,826
  • 2
  • 32
  • 53
6
votes
5 answers

Why are gettimeofday() intervals occasionally negative?

I have an experimental library whose performance I'm trying to measure. To do this, I've written the following: struct timeval begin; gettimeofday(&begin, NULL); { // Experiment! } struct timeval end; gettimeofday(&end, NULL); // Print the time…
Andres Jaan Tack
  • 22,566
  • 11
  • 59
  • 78
5
votes
2 answers

clock_gettime() Vs. gettimeofday() for measuring OpenMP execution time

I am working on some C code that is implementing a triple nested for loop to calculate matrix-matrix multiplication while parallelizing it using OpenMP. I am trying to accurately measure the amount of time it takes from when the for loop starts to…
Shaun Holtzman
  • 201
  • 2
  • 9
5
votes
2 answers

What is the unit of gettimeofday()?

I've a program to calculate the latency of an object in a pub-sub model. I've used the following function for timestamp: uint64_t GetTimeStamp() { struct timeval tv; gettimeofday(&tv,NULL); return…
John
  • 73
  • 1
  • 1
  • 4
5
votes
4 answers

time vs gettimeofday c ++

The time command returns the time elapsed in execution of a command. If I put a "gettimeofday()" at the start of the command call (using system() ), and one at the end of the call, and take a difference, it doesn't come out the same. (its not a very…
sushant-hiray
  • 1,838
  • 2
  • 21
  • 28
4
votes
3 answers

What is the precision of the gettimeofday function?

I am reading the chapter single.dvi of OSTEP. In the homework part, it says: One thing you’ll have to take into account is the precision and accuracy of your timer. A typical timer that you can use is gettimeofday(); read the man page for details.…
shino
  • 71
  • 7
4
votes
1 answer

gettimeofday - explanation of the exact struct timeval fields' meaning

I'm trying to write a simple function in C that would calculate the difference between two moments in nanoseconds. To do this, I thought of using the function gettimeofday, which updates the given struct timeval's fields. As the man page said, the…
Zach
  • 537
  • 4
  • 9
  • 19
4
votes
1 answer

‘getnstimeofday' is an implicit declaration in system call when is included

Anwser Solved!! Thanks to @IanAbbott the header should be: #include #include rather than . More detail see discussion. Original Question I am writing a system call names sys_my_time.c, which will…
tigercosmos
  • 345
  • 3
  • 17
4
votes
4 answers

Object-oriented representation of date and time in C++

I am writing C++ code for an embedded Linux system. Traditionally, on Linux, the date and time would be retrieved by calling the library function gettimeofday(). But that doesn't feel very object-oriented to me. I would like to instead be able to…
mikelong
  • 3,694
  • 2
  • 35
  • 40
1
2 3 4 5 6 7