Skip to content

Commit 7daad2c

Browse files
committed
Benchmark symlink
1 parent 112e0a7 commit 7daad2c

File tree

6 files changed

+112
-64
lines changed

6 files changed

+112
-64
lines changed

+stdlib/+dotnet/read_symlink.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
%% DOTNET.READ_SYMLINK resolve the symbolic links of a filepath
2+
% .NET >= 6 required
23

34
function r = read_symlink(file)
45

5-
r = "";
6-
76
try
87
h = System.IO.FileInfo(file);
98
r = string(h.LinkTarget);
@@ -13,6 +12,7 @@
1312
end
1413
catch e
1514
dotnetException(e)
15+
r = "";
1616
end
1717

1818
end

+stdlib/+sys/read_symlink.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
cmd = sprintf('readlink -fn "%s"', file);
1010
else
1111
cmd = sprintf('pwsh -c "(Get-Item -Path ''%s'').Target"', file);
12+
13+
% cmd = sprintf('fsutil reparsepoint query "%s"', file);
14+
% worried if searching for "Tag value: Symbolic Link" might be locale dependent
1215
end
1316

1417
if stdlib.is_symlink(file)

example/BenchmarkIsSymlink.m

Lines changed: 0 additions & 59 deletions
This file was deleted.

example/BenchmarkIsSymlinkRun.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function [r, s] = BenchmarkIsSymlinkRun()
2-
tname = "BenchmarkIsSymlink";
2+
tname = "BenchmarkSymlink";
33

44
%% Exist
5-
r.same = run_bench(tname + "/bench_exist");
5+
r.same = run_bench(tname + "/bench_is_symlink_exist");
66
s.exist = sampleSummary(r.same);
77
disp(sortrows(s.exist, "Median"))
88
%% Not Exist
9-
r.not = run_bench(tname + "/bench_not_exist");
9+
r.not = run_bench(tname + "/bench_is_symlink_not_exist");
1010
s.not = sampleSummary(r.not);
1111
disp(sortrows(s.not, "Median"))
1212

example/BenchmarkReadSymlinkRun.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function [r, s] = BenchmarkReadSymlinkRun()
2+
tname = "BenchmarkSymlink";
3+
4+
%% Exist
5+
r.same = run_bench(tname + "/bench_read_symlink_exist");
6+
s.exist = sampleSummary(r.same);
7+
disp(sortrows(s.exist, "Median"))
8+
%% Not Exist
9+
r.not = run_bench(tname + "/bench_read_symlink_not_exist");
10+
s.not = sampleSummary(r.not);
11+
disp(sortrows(s.not, "Median"))
12+
13+
end
14+
15+
16+
function result = run_bench(name)
17+
suite = testsuite(name);
18+
exp = matlab.perftest.TimeExperiment.limitingSamplingError(MaxSamples=20, RelativeMarginOfError=0.1);
19+
result = exp.run(suite);
20+
end

example/BenchmarkSymlink.m

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture("..")}) ...
2+
BenchmarkSymlink < matlab.perftest.TestCase
3+
4+
properties
5+
link
6+
target
7+
not_exist = tempname()
8+
end
9+
10+
properties(TestParameter)
11+
is_backend
12+
rs_backend
13+
end
14+
15+
methods (TestParameterDefinition, Static)
16+
function [is_backend, rs_backend] = setupBackend()
17+
is_backend = init_backend('is_symlink');
18+
rs_backend = init_backend('read_symlink');
19+
end
20+
end
21+
22+
23+
methods(TestClassSetup)
24+
function setup_symlink(tc)
25+
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture())
26+
27+
tc.link = fullfile(pwd(), 'my.lnk');
28+
29+
tc.target = [mfilename("fullpath") '.m'];
30+
31+
tc.assertTrue(stdlib.create_symlink(tc.target, tc.link))
32+
end
33+
end
34+
35+
36+
methods (Test, TestTags={'is_symlink'})
37+
38+
function bench_is_symlink_exist(tc, is_backend)
39+
tc.startMeasuring()
40+
i = stdlib.is_symlink(tc.link, is_backend);
41+
tc.stopMeasuring()
42+
43+
tc.verifyClass(i, 'logical')
44+
tc.verifyTrue(i)
45+
end
46+
47+
48+
function bench_is_symlink_not_exist(tc, is_backend)
49+
tc.startMeasuring()
50+
i = stdlib.is_symlink(tc.not_exist, is_backend);
51+
tc.stopMeasuring()
52+
53+
tc.verifyClass(i, 'logical')
54+
tc.assertNotEmpty(i)
55+
tc.verifyFalse(i)
56+
end
57+
58+
end
59+
60+
61+
methods (Test, TestTags={'read_symlink'})
62+
63+
function bench_read_symlink_exist(tc, rs_backend)
64+
tc.startMeasuring()
65+
i = stdlib.read_symlink(tc.link, rs_backend);
66+
tc.stopMeasuring()
67+
68+
tc.verifyClass(i, 'string')
69+
tc.verifyGreaterThan(strlength(i), 0)
70+
end
71+
72+
73+
function bench_read_symlink_not_exist(tc, rs_backend)
74+
tc.startMeasuring()
75+
i = stdlib.read_symlink(tc.not_exist, rs_backend);
76+
tc.stopMeasuring()
77+
78+
tc.verifyClass(i, 'string')
79+
tc.verifyEqual(strlength(i), 0)
80+
end
81+
82+
end
83+
84+
end

0 commit comments

Comments
 (0)