Questions tagged [gettimeofday]

The tag has no usage guidance, but it has a tag wiki.

gettimeofday
Filter by
Sorted by
Tagged with
32 votes
5 answers
43k views

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 ...
Humble Debugger's user avatar
12 votes
4 answers
77k views

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 <windows....
make's user avatar
  • 775
22 votes
4 answers
94k views

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

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 ...
dicroce's user avatar
  • 46.1k
21 votes
3 answers
13k views

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 ...
Josh Kelley's user avatar
  • 57.3k
3 votes
1 answer
2k views

Swift: gettimeofday and Unsafe Pointers

The code in Swift ... var time:timeval? gettimeofday(UnsafePointer<timeval>, UnsafePointer<()>) // this is the method expansion before filling in any data ... The code in Objective C ......
solenoid's user avatar
  • 994
2 votes
1 answer
3k views

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 ...
Anonymous's user avatar
2 votes
2 answers
2k views

usleep() to calculate elapsed time behaves weird

I am calculating time elapsed in milli seconds for each successive call to handler function using the code below. When i use usleep(1000) i.e. 1 ms time difference between each call is 10 ms and when ...
vikas_2kx's user avatar
3 votes
2 answers
8k views

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; ...
user1106106's user avatar
2 votes
1 answer
493 views

OSX gettimeofday syscall on x86_64 seems to not work

I'm making a call to gettimeofday via the syscall instruction using 64bit code. I can't get any results back and am getting told via Dtrace that the call worked with no errors, but the registers I ...
Chris Hinsley's user avatar
1 vote
3 answers
2k views

Strange errors using timeval struct and gettimeofday —because of semicolon in #define

I am getting a couple of weird compilation errors. This is for a homework assignment (help is ok). The idea is to implement a program that tests how well the user can hit "enter" once a second. I'm ...
MCP's user avatar
  • 4,466
1 vote
5 answers
2k views

Strange results while measuring delta time on Linux

Update: fixed delta calculations in code, still the issue remains Folks, could you please explain why I'm getting very strange results from time to time using the following code: #include <unistd.h&...
pachanga's user avatar
  • 3,023
0 votes
4 answers
1k views

Python clock function on FreeBSD

While testing Pythons time.clock() function on FreeBSD I've noticed it always returns the same value, around 0.156 The time.time() function works properly but I need a something with a slightly ...
Dan's user avatar
  • 720
0 votes
4 answers
1k views

gettimeofday clock_gettime solution to generate unique number

My process runs multiple instances (processes) and multiple threads and all of them write to the same database. As soon as the request is placed, a unique req id is generated for the record to be ...
Kiran's user avatar
  • 1,003
0 votes
2 answers
2k views

getting chrono time in specific way

I have following C code: uint64_t combine(uint32_t const sec, uint32_t const usec){ return (uint64_t) sec << 32 | usec; }; uint64_t now3(){ struct timeval tv; gettimeofday(&tv,...
Nick's user avatar
  • 10.3k
0 votes
1 answer
10k views

Timeval struct usage

I needed to calculate the time it takes to run a certain function and ran into the following code,record & output the execution time of a piece of code in nanoseconds And also is there any ...
Siva's user avatar
  • 141
0 votes
1 answer
2k views

Why changing timezone from shell does not affect gettimeofday() even after reboot?

I have changed on Ubuntu timezone using dpkg-reconfigure tzdata from UTC+2 to UTC+0 but running C code gettimeofday() still showing tz_minuteswest and tv_sec in previous timezone even after reboot. ...
Javier Hernández's user avatar