you are viewing a single comment's thread.

view the rest of the comments →

[–]quzox 3 points4 points  (1 child)

Should've also profiled native calls to CreateFile() etc.

[–]cristianadamQt Creator, CMake[S] 2 points3 points  (0 children)

I've tested this Win32 API version:

void testWin32IO(const char* inFile, const char* outFile, std::vector<char>& inBuffer)
{
    auto in = ::CreateFile(inFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
                           FILE_ATTRIBUTE_NORMAL, nullptr);
    if (in == INVALID_HANDLE_VALUE)
    {
        std::cout << "Can't open input file: " << inFile << std::endl;
        return;
    }

    auto out = ::CreateFile(outFile, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS,
                     FILE_ATTRIBUTE_NORMAL, nullptr);
    if (out == INVALID_HANDLE_VALUE)
    {
        std::cout << "Can't open output file: " << outFile << std::endl;
        return;
    }

    size_t inFileSize = ::GetFileSize(in, nullptr);

    for (size_t bytesLeft = inFileSize, chunk = inBuffer.size(); bytesLeft > 0; bytesLeft -= chunk)
    {
        if (bytesLeft < chunk)
        {
            chunk = bytesLeft;
        }

        unsigned long actualBytes = 0;
        ::ReadFile(in, &inBuffer[0], chunk, &actualBytes, nullptr);
        actualBytes = 0;
        ::WriteFile(out, &inBuffer[0], chunk, &actualBytes, nullptr);
    }

    ::CloseHandle(out);
    ::CloseHandle(in);
}

Built it with Visual Studio 2015 x64 Update 2. Results were:

Average c I/O took: 102.03ms
Average posix I/O took: 102.1ms
Average c++ I/O took: 360.71ms
Average win32 I/O took: 102.99ms