The correct way to register elapsed time in C ++

I am doing an article on GPU acceleration in a cluster environment
For this, I program in CUDA, it is basically a C ++ extension. But, since I am a C # developer, I do not know the features of C ++.

Is there any concern about the elapsed registration time? Some suggestion or blog to read.

My initial idea is to make a big loop and run the program several times. 50 ~ 100, and record every elapsed time to make some speed graphs.

+4
source share
3 answers

Standard features like time often have very low resolution. And yes, a good way to get around this is to repeatedly conduct your test and take the average. Please note that the first few times can be excessively slow due to hidden startup costs - especially when using complex resources such as GPUs.

For platform-specific calls, see QueryPerformanceCounter on Windows and CFAbsoluteTimeGetCurrent on OS X. (I haven't used the POSIX call to clock_gettime , but it might be worth checking out.)

Measuring GPU performance is difficult because GPUs are remote processing units that execute separate instructions — often on many parallel devices. You might want to visit the Nvidia CUDA Zone for various resources and tools that will help you measure and optimize your CUDA code. (Resources related to OpenCL are also very relevant.)

Ultimately, you want to see how quickly your results hit the screen, right? For this reason, calling for time may be enough for your needs.

+2
source

Depending on your needs, this can be easy:

 time_t start = time(NULL); // long running process printf("time elapsed: %d\n", (time(NULL) - start)); 

I think you need to tell how you plan to register it (file or console) and what is your accuracy (seconds, ms, us, etc.). "time" gives it in seconds.

+4
source

I would recommend using the accelerator accelerator library . This is platform agnostic and simple:

 #include <boost/timer/timer.hpp> boost::timer t; // do some stuff, up until when you want to start timing t.restart(); // do the stuff you want to time. std::cout << t.elapsed() << std::endl; 

Of course t.elapsed () returns a double, which you can save in a variable.

+3
source

All Articles