Skip to content

Commit e7d2471

Browse files
committed
windows: disk{available,capacity}: 4x faster with .NET
1 parent ee6f062 commit e7d2471

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

+stdlib/disk_available.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% DISK_AVAILABLE disk available space (bytes)
2-
% requires: mex or java
2+
% optional: mex
33
%
44
% example: stdlib.disk_available('/')
55
%
@@ -10,10 +10,12 @@
1010
d {mustBeTextScalar}
1111
end
1212

13-
f = javaFileObject(d).getUsableSpace();
14-
15-
f = uint64(f);
16-
13+
if ispc()
14+
% 4x faster than Java
15+
f = System.IO.DriveInfo(d).AvailableFreeSpace();
16+
else
17+
f = javaFileObject(d).getUsableSpace();
18+
f = uint64(f);
1719
end
1820

1921
%!assert (disk_available('.') > 0)

+stdlib/disk_capacity.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% DISK_CAPACITY disk total capacity (bytes)
2-
% requires: mex or java
2+
% optional: mex
33
%
44
% example: stdlib.disk_capacity('/')
55

@@ -8,9 +8,13 @@
88
d {mustBeTextScalar}
99
end
1010

11-
f = javaFileObject(d).getTotalSpace();
12-
13-
f = uint64(f);
11+
if ispc()
12+
% 4x faster than Java
13+
f = System.IO.DriveInfo(d).TotalSize();
14+
else
15+
f = javaFileObject(d).getTotalSpace();
16+
f = uint64(f);
17+
end
1418

1519
end
1620

0 commit comments

Comments
 (0)