UPD 2017: these are early experimnts on c++ compiler optimizations. I don’t think it is useful any more.
I have the following code for copying several buffers from one object to another:
|
|
Array conf_
is defined as follows:
|
|
BYTE is unsigned char. That code is written with no doubt about software performance. It just works. When I do so I hope compiler make it better for me. This fragment takes about 45 ms for copying of 2 images with ( 1980x1080 pixels ) x 3 planes = 6.2 MPixels. I use Microsoft Visual Studio 2008 compiler on Intel Core i7 950 @ 3.07 GHz. The code is built for x64 platform. Disabled compiler option for buffer security check (GS-) and debug information has no effect on the productivity.
Slightly better solution:
|
|
It takes about **35 ms **per full copy.
Much better solution:
|
|
Everything is the same except for using additional temporary variable. This version runs for 8 ms. UPD: Intel Compiler 2011 demonstrates 2 ms latency for this code.
And even better solution for Visual Studio:
|
|
It uses **copy **function from standard C++ library. Time of this version is 2 ms.
UPD: Intel Compiler 2011 demonstrates 2 ms latency for this code too, but it seems that for multiple runs the last version is slightly slower than previous one for ICC. My previous time measuremets have integer precision. So for 50 frames ICC+last-version got 141 ms and ICC+previous-version got 112 ms. That is strange.
On Intel Compiler memcpy and std::copy
give nearly the same results.