Skip to content

Commit 905c83f

Browse files
committed
canonical benchmark
1 parent 8703a7f commit 905c83f

File tree

7 files changed

+64
-19
lines changed

7 files changed

+64
-19
lines changed

+stdlib/canonical.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
%%% Outputs
1313
% * c: canonical path, if determined
1414

15-
function c = canonical(p, strict)
15+
function [c, b] = canonical(p, strict)
1616
arguments
1717
p string
1818
strict (1,1) logical = false
1919
end
2020

2121
try
2222
c = stdlib.native.canonical(p, strict);
23+
b = 'native';
2324
catch e
2425
switch e.identifier
2526
case {'MATLAB:UndefinedFunction', 'MATLAB:undefinedVarOrClass'}
2627
c = stdlib.legacy.canonical(p, strict);
28+
b = 'legacy';
2729
otherwise
2830
rethrow(e)
2931
end

example/BenchmarkCanonical.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture("..")}) ...
2+
BenchmarkCanonical < matlab.perftest.TestCase
3+
4+
properties
5+
exist = '.'
6+
not_exist = tempname()
7+
end
8+
9+
properties(TestParameter)
10+
fun = {@stdlib.native.canonical, @stdlib.legacy.canonical}
11+
end
12+
13+
14+
methods (Test)
15+
16+
function bench_exist(tc, fun)
17+
tc.startMeasuring()
18+
o = fun(tc.exist, true);
19+
tc.stopMeasuring()
20+
21+
tc.verifyClass(o, 'string')
22+
tc.verifyGreaterThan(strlength(o), 0)
23+
end
24+
25+
26+
function bench_not_exist(tc, fun)
27+
tc.startMeasuring()
28+
o = fun(tc.not_exist, true);
29+
tc.stopMeasuring()
30+
31+
tc.verifyClass(o, 'string')
32+
tc.verifyEqual(strlength(o), 0)
33+
end
34+
35+
end
36+
37+
end

example/BenchmarkCanonicalRun.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function [r, s] = BenchmarkCanonicalRun()
2+
tname = "BenchmarkCanonical";
3+
4+
%% Exist
5+
r.same = run_bench(tname + "/bench_exist");
6+
s.exist = sampleSummary(r.same);
7+
disp(sortrows(s.exist, "Median"))
8+
%% Not Exist
9+
r.not = run_bench(tname + "/bench_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=150, RelativeMarginOfError=0.05);
19+
result = exp.run(suite);
20+
end

example/bench_absolute.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
%f = "abc";
77

8-
fno = @() stdlib.absolute(f, false);
8+
fno = @() stdlib.absolute(f);
99

1010
t_no = timeit(fno);
1111

12-
disp("No Java: " + t_no + " s")
12+
disp(t_no + " s")

example/bench_canonical.m

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

example/bench_exists.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
t_no = timeit(fno);
77

8-
disp("No Java: " + t_no + " s")
8+
disp(t_no + " s")

example/bench_homedir.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
t_no = timeit(fno);
66

7-
disp("No Java: " + t_no + " s")
7+
disp(t_no + " s")

0 commit comments

Comments
 (0)