Whats the fastest way to get the size of a directory? Is multithreading possibile?
How can I find the size of all files located inside a folder?
Size of a directory
No other questions on stackoverflow & other sites mention multithreading but it should be possibile like if the directory contains other directories..
The other solutions on stackoverflow are pretty slow , slower even than
Windows Folder->Properties dialog even on Release...
Tried all the solutions on stack-overflow and they are either not compiling or very slow...
CodePudding user response:
Whats the fastest way to get the size of a directory?
By "size of a directory", I suppose that you mean cumulative size of files in the directory and its descendants.
In general, the solution is to traverse the directory tree, get the size of each file, and accumulate.
There is no one solution that is fastest in all use cases. It always depends on details.
Is multithreading possibile?
Certainly. However, it's hard to guarantee that you would get better performance with multi-threading.
Problem is that the computational cost of the operation is trivial, while the bottleneck is reading the file system. If each thread is waiting for a storage device, then you might not get any speedup. In fact, if the storage device is a spinning disk, then parallel read will likely be much slower.