Performance Issue
Vino.B via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Sep 6 01:10:35 PDT 2017
On Tuesday, 5 September 2017 at 10:28:28 UTC, Stefan Koch wrote:
> On Tuesday, 5 September 2017 at 09:44:09 UTC, Vino.B wrote:
>> Hi,
>>
>> The below code is consume more memory and slower can you
>> provide your suggestion on how to over come these issues.
>>
>> [...]
>
> Much slower then ?
Hi,
This code is used to get the size of folders on a NetApp NAS
Filesystem , so the NetApp have their own tool to perform such
task which is faster than this code, the difference is about
15-20 mins. While going through this website i was able to findd
that we can use the "fold" from std.algorithm.iteration which
would be faster that use the normal "+=", so tried replacing the
line "{ subdirTotal += f[0]; }" with { subdirTotal = f[0].fold!(
(a, b) => a + b); }, and this produces the required output+
additional output , in the next line of the code i say to list
only folders that are greater than 10 Mb but this now is listing
all folder (folder whose size is less than 10 MB are getting
listed, not sure why.
Program:
string[][] coSizeDirList (string FFs, int SizeDir) {
ulong subdirTotal = 0;
ulong subdirTotalGB;
auto Subdata = appender!(string[][]); Subdata.reserve(100);
auto dFiles = dirEntries(FFs, SpanMode.shallow).filter!(a =>
a.isDir && !globMatch(a.baseName, "*DND*")).map!(a =>
tuple(a.name, a.size)).array;
foreach (d; dFiles) {
auto SdFiles = dirEntries(join(["\\\\?\\", d[0]]),
SpanMode.depth).map!(a => tuple(a.size)).array;
foreach (f; parallel(SdFiles,1))
{ subdirTotal = f[0].fold!( (a, b) => a + b); }
subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Subdata ~= [d[0],
to!string(subdirTotalGB)]; }
subdirTotal = 0;
}
return Subdata.data;
}
OutPut
C:\Temp\TEAM1\dir1 - > Sieze greater than 10MB
C:\Temp\TEAM1\dir2 -> Size lesser than 10MB.
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list