gettimeofday

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 higher resolution. Does anyone the C function it's bound to and if there is an alternative high resolution timer? I'm not profiling so the Tim...

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 implement by calling gettimeofday() before and after I call select() and then using timersub(...

What's the best alternative library to gettimeofday() in C++?

Hi, Is there a more Object Oriented alternative to using gettimeofday() in C++ on linux? I like for instance to be able to write code similar to this: DateTime now = new DateTime; DateTime duration = new DateTime(2300, DateTime.MILLISECONDS) DateTime deadline = now + duration; while(now < deadline){ DoSomething(); delete now;...

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

Hi, 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.h> #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #else #define DELTA_EPOCH_I...

Measuring execution time of selected loops

I want to measure the running times of selected loops in a C program so as to see what percentage of the total time for executing the program (on linux) is spent in these loops. I should be able to specify the loops for which the performance should be measured. I have tried out several tools (vtune, hpctoolkit, oprofile) in the last few ...

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 it took! std::cout << "Time: " << 100000 * (end.tv_sec - begin.tv_sec) + (end.tv_usec - ...

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 the following code: #include <unistd.h> #include <sys/time.h> #include <stdio.h> int main() { struct timeval start, end; long mtime1, mtime2, diff; while(1) { g...

Error with -mno-sse flag and gettimeofday() in C

A simple C program which uses gettimeofday() works fine when compiled without any flags ( gcc-4.5.1) but doesn't give output when compiled with the flag -mno-sse. #include <stdio.h> #include <stdlib.h> int main() { struct timeval s,e; float time; int i; gettimeofday(&s, NULL); for( i=0; i< 10000; i++); gettimeof...

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 suggest the method to get the system clock in milliseconds (I may settle with seconds if I can...

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 added to the proprietary db. Here are our limitations: It cannot be more than 9 char length, needs to have hhmmss as the first 6 chars. We deci...

logical time versus physical time in ubuntu linux

Hi, i am measuring physical time between two events like this: #include <time.h> #include <sys/time.h> timeval wall_time0; timeval wall_time1; // start of period measurement gettimeofday( &wall_time0 , 0); ...stuff happening // end of period measurement gettimeofday( &wall_time1 , 0); return ( ( wall_time1.tv_sec - wall_time0.tv_...