Skip to content

Commit 46ee9c3

Browse files
committed
is_symlink: prefer native as it's 4x faster
1 parent 42f687e commit 46ee9c3

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

+stdlib/+native/is_symlink.m

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

+stdlib/is_symlink.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
backend (1,:) string = ["native", "java", "python", "dotnet", "sys"]
1414
end
1515

16-
o = stdlib.Backend(mfilename(), backend);
17-
18-
if isscalar(file)
19-
ok = o.func(file);
16+
if backend(1) == "native"
17+
try
18+
ok = isSymbolicLink(file);
19+
b = "native";
20+
catch e
21+
if e.identifier ~= "MATLAB:UndefinedFunction"
22+
rethrow(e)
23+
end
24+
end
2025
else
21-
ok = arrayfun(o.func, file);
26+
o = stdlib.Backend(mfilename(), backend);
27+
b = o.backend;
28+
ok = o.func(file);
2229
end
2330

24-
b = o.backend;
25-
2631
end

example/BenchmarkIsSymlinkRun.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515

1616
function result = run_bench(name)
1717
suite = testsuite(name);
18-
exp = matlab.perftest.TimeExperiment.limitingSamplingError(MaxSamples=20, RelativeMarginOfError=0.1);
18+
exp = matlab.perftest.TimeExperiment.limitingSamplingError(MaxSamples=50, RelativeMarginOfError=0.1);
1919
result = exp.run(suite);
2020
end

example/BenchmarkSymlink.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
methods (TestParameterDefinition, Static)
1616
function [is_backend, rs_backend] = setupBackend()
17-
is_backend = init_backend('is_symlink');
17+
is_backend = cellstr(["native", init_backend('is_symlink')]);
1818
rs_backend = init_backend('read_symlink');
1919
end
2020
end

test/TestSymlink.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ function test_is_symlink(tc, p, B_is_symlink)
5151
tc.verifyEqual(stdlib.is_symlink(p{1}, B_is_symlink), p{2}, p{1})
5252
end
5353

54-
function test_is_symlink_array(tc, B_is_symlink)
55-
r = stdlib.is_symlink([tc.link, mfilename() + ".m"], B_is_symlink);
56-
tc.verifyEqual(r, [true, false], "failed to detect own link")
57-
end
58-
5954

6055
function test_read_symlink_empty(tc, Pre, B_read_symlink)
6156
tc.verifyEqual(stdlib.read_symlink(Pre, B_read_symlink), "")

0 commit comments

Comments
 (0)