This code:

```
#include <memory>
#include <time.h>
#include <chrono>
#include <thread>
#include <stdio.h>
#include <stdlib.h>

void Test( ) {
#define current_milliseconds std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now( ).time_since_epoch( ) ).count( )
    int *c = ( int* )malloc( 1024 * 1024 * 1024 );
    int result = 0;
    auto millis = -current_milliseconds;
    //clock_t timer = -clock( );
    for ( int i = 0 ; i < 1024 * 1024 * 256 /* 1024 / 4 */; ++i )
        result += c[ i ];
    millis += current_milliseconds;
    printf( "Took: %ldms (JUST PASSING BY: %d)\n", millis, result );
    free( c );
#undef current_milliseconds
}

int main( ) {
    std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
    Test( );
    std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
    Test( );
    return -1;
}

```

I ran 7 tests and gave the last 6 outputs:

```
Took: 502ms (JUST PASSING BY: 0)
Took: 607ms (JUST PASSING BY: 0)

Took: 480ms (JUST PASSING BY: 0)
Took: 588ms (JUST PASSING BY: 0)

Took: 492ms (JUST PASSING BY: 0)
Took: 562ms (JUST PASSING BY: 0)

Took: 506ms (JUST PASSING BY: 0)
Took: 558ms (JUST PASSING BY: 0)

Took: 470ms (JUST PASSING BY: 0)
Took: 555ms (JUST PASSING BY: 0)

Took: 510ms (JUST PASSING BY: 0)
Took: 562ms (JUST PASSING BY: 0)

```

If your output is different, then try to run the executable again (Hard-disk cache misses) or try to enlarge the number of iterations and allocated bytes (Have a feeling).

Notice that the timer's code range is only on the loop and not the allocation too; then there goes the question again: why the second iteration is slower? Is there a way to fix it?

Additional Information:

1. That PC has pentium 2.8GHZ @ 2 cores (Intel E6300) processor, 4GB RAM (had 2.2GB free RAM before executing the tests), and enterprise Intel SSD.
2. It seem that while executing the tests, it wrote a few of 100MBs. Why it did when it had enough free RAM? (I deallocated 1GB and then allocated another 1GB, it shouldn't pass pre-swapfile it)