首页 > 解决方案 > Large binary read in windows 10 is faster when run as admin

问题描述

I have an application that reads large binary files and all is well, but it runs much faster as admin than via my normal account. Can someone please help me understand why?

The sample application below exhibits the issue. Some specifics: Windows 10.0.19041 C++11 built in Visual Studio 2019 (as x64). Stand alone machine, no domain, just a normal user account with admin privileges, and the test file is local.

#include <chrono>
#include <fstream>
#include <iostream>

int main()
{
    auto aFile = R"(SomeLargeBinaryFile)";
    std::ifstream fileStream(aFile, std::ios::binary);
    
    typedef std::chrono::high_resolution_clock TheClock;
    auto startTime = TheClock::now();

    int offset = (int)2e8;
    fileStream.seekg(offset);
    
    int bucketSize = (int)3.75e8;
    double* bucket = new double[bucketSize]();

    fileStream.read(reinterpret_cast<char*>(bucket), sizeof(double) * bucketSize);

    auto endTime = TheClock::now();
    auto elapsed = endTime - startTime;
    auto elapsedMS = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
    auto elapsedSec = elapsedMS.count() / 1000.0;

    std::cout << " Sample reader elapsed seconds: " << elapsedSec << std::endl;

    fileStream.close();
    delete[] bucket;
}

标签: c++windowsperformanceadminbinaryfiles

解决方案


推荐阅读