c++ - speed up a file scan crc algorithm -


i trying scan folder 1000 files of 1.4 gb in total takes 10 minutes on lot of computers, unacceptable. coded below , know how can speed up, if possible. note files never on 250mb, hence buffer. code run against each file in folder.

handle hfile = createfilea(szfilepath, generic_read, file_share_read, null, open_existing, 0, null); if (hfile != invalid_handle_value) {     dword dwsize = getfilesize(hfile, null);     if (dwsize != -1)     {         if (dwsize > 0)         {             dword dwchecksum = 0;             dword dwreads = 0;             dword dwreadfar = 0;             bool bfailed = false;              if (readfile(hfile, pfilebuffer, 250000000, &dwreads, null))             {                 dwchecksum = calculatechksum(pfilebuffer, dwreads);             }             else             {                 bfailed = true;             }         }     } }  dword calculatechksum(byte* pdata, int len, dword crc) {     dword  crc = crc;     const dword* current = (const dword*)pdata;      while (len >= 4)     {         crc = *current++ + crc;         len -= 4;     }      const byte* currentchar = (const byte*)current;     while (len-- > 0)         crc = *currentchar++ + crc;      return crc; } 

your cpu idling when file partially read. speed up, read 1 mb chunks , decode them on fly. pass file_flag_sequential_scan createfile windows know prefetch next chunks.

also, make sure test optimized build. function simple enough single thread should keep disk i/o, might not case in debug builds.

btw, know that's not crc ? algorithm fails catch trivial modifications such endianness swapping.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -