Why is the release of the memset version slower than the debug version in visual studio 2012?

Why is the memset version version slower than the debug version in visual studio 2012? in visual sutido 2010, this is also the result. My computer:

Intel Core i7-3770 3.40 GHz Memory 8G Operating systems: windows 7 sp1 64bit

this is my test code:

#include <boost/progress.hpp>

int main()
{
    const int Size = 1000*1024*1024;
    char* Data = (char*)malloc(Size);

#ifdef _DEBUG
    printf_s("debug\n");
#else
    printf_s("release\n");
#endif

    boost::progress_timer timer;
    memset(Data, 0, Size);

    return 0;
}

conclusion:

release
0.27 s

debug
0.06 s

edited by:

if i change code to this, it will get the same result:

#include <boost/progress.hpp>

int main()
{
    const int Size = 1000*1024*1024;
    char* Data = (char*)malloc(Size);
    memset(Data, 1, Size);

#ifdef _DEBUG
    printf_s("debug\n");
#else
    printf_s("release\n");
#endif

    {
        boost::progress_timer timer;
        memset(Data, 0, Size);
    }    

    return 0;
}

so Hans Passant is right, thank you very much.

+4
source share
1 answer

, memset() . , , . , .

, Windows, malloc() . . . , . โ€‹โ€‹ , . , , , .

, memset(), . . , , . , , , . , DDR3 266 , .

, CRT. , . , malloc() .

+18

Source: https://habr.com/ru/post/1543390/


All Articles