Skip to content

Commit 419a096

Browse files
committed
benchmark:inode,canonical: improve accuracy
1 parent 4a50fa9 commit 419a096

File tree

4 files changed

+53
-26
lines changed

4 files changed

+53
-26
lines changed

example/BenchmarkCanonical.m

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,29 @@
1414
methods (Test)
1515

1616
function bench_exist(tc, fun)
17-
tc.startMeasuring()
18-
o = fun(tc.exist, true);
19-
tc.stopMeasuring()
17+
while(tc.keepMeasuring)
18+
o = fun(tc.exist, true);
19+
end
20+
21+
tc.verifyClass(o, 'string')
22+
tc.verifyGreaterThan(strlength(o), 0)
23+
end
24+
25+
26+
function bench_exist_main(tc)
27+
while(tc.keepMeasuring)
28+
o = stdlib.canonical(tc.exist, true);
29+
end
2030

2131
tc.verifyClass(o, 'string')
2232
tc.verifyGreaterThan(strlength(o), 0)
2333
end
2434

2535

2636
function bench_not_exist(tc, fun)
27-
tc.startMeasuring()
28-
o = fun(tc.not_exist, true);
29-
tc.stopMeasuring()
37+
while(tc.keepMeasuring)
38+
o = fun(tc.not_exist, true);
39+
end
3040

3141
tc.verifyClass(o, 'string')
3242
tc.verifyEqual(strlength(o), 0)

example/BenchmarkCanonicalRun.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
function [r, s] = BenchmarkCanonicalRun()
1+
function BenchmarkCanonicalRun()
22
tname = "BenchmarkCanonical";
33

44
%% Exist
55
r.same = run_bench(tname + "/bench_exist");
6-
s.exist = sampleSummary(r.same);
7-
disp(sortrows(s.exist, "Median"))
6+
s.exist = sortrows(sampleSummary(r.same), "Median");
7+
disp(s.exist(:, ["Name", "SampleSize", "Mean", "Median"]))
88
%% Not Exist
99
r.not = run_bench(tname + "/bench_not_exist");
10-
s.not = sampleSummary(r.not);
11-
disp(sortrows(s.not, "Median"))
12-
10+
s.not = sortrows(sampleSummary(r.not), "Median");
11+
disp(s.not(:, ["Name", "SampleSize", "Mean", "Median"]))
12+
%% Main
13+
r.main = run_bench(tname + "/bench_exist_main");
14+
s.main = sortrows(sampleSummary(r.main), "Median");
15+
disp(s.main(:, ["Name", "SampleSize", "Mean", "Median"]))
1316
end
1417

1518

1619
function result = run_bench(name)
1720
suite = testsuite(name);
18-
exp = matlab.perftest.TimeExperiment.limitingSamplingError(MaxSamples=150, RelativeMarginOfError=0.05);
21+
exp = matlab.perftest.TimeExperiment.limitingSamplingError(RelativeMarginOfError=0.05);
1922
result = exp.run(suite);
2023
end

example/BenchmarkInode.m

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
methods (Test)
2222

2323
function bench_exist(tc, backend)
24-
tc.startMeasuring()
25-
i = tc.fun(tc.exist, backend);
26-
tc.stopMeasuring()
24+
while tc.keepMeasuring()
25+
i = tc.fun(tc.exist, backend);
26+
end
27+
28+
tc.verifyClass(i, 'uint64')
29+
tc.assertNotEmpty(i)
30+
tc.verifyGreaterThan(i, 0)
31+
end
32+
33+
34+
function bench_exist_main(tc)
35+
while tc.keepMeasuring()
36+
i = tc.fun(tc.exist);
37+
end
2738

2839
tc.verifyClass(i, 'uint64')
2940
tc.assertNotEmpty(i)
@@ -32,9 +43,9 @@ function bench_exist(tc, backend)
3243

3344

3445
function bench_not_exist(tc, backend)
35-
tc.startMeasuring()
36-
i = tc.fun(tc.not_exist, backend);
37-
tc.stopMeasuring()
46+
while tc.keepMeasuring()
47+
i = tc.fun(tc.not_exist, backend);
48+
end
3849

3950
tc.verifyClass(i, 'uint64')
4051
tc.verifyEmpty(i)

example/BenchmarkInodeRun.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
function [r, s] = BenchmarkInodeRun()
1+
function BenchmarkInodeRun()
22
tname = "BenchmarkInode";
33

44
%% Exist
55
r.same = run_bench(tname + "/bench_exist");
6-
s.exist = sampleSummary(r.same);
7-
disp(sortrows(s.exist, "Median"))
6+
s.exist = sortrows(sampleSummary(r.same), "Median");
7+
disp(s.exist(:, ["Name", "SampleSize", "Mean", "Median"]))
88
%% Not Exist
99
r.not = run_bench(tname + "/bench_not_exist");
10-
s.not = sampleSummary(r.not);
11-
disp(sortrows(s.not, "Median"))
12-
10+
s.not = sortrows(sampleSummary(r.not), "Median");
11+
disp(s.not(:, ["Name", "SampleSize", "Mean", "Median"]))
12+
%% Main
13+
r.main = run_bench(tname + "/bench_exist_main");
14+
s.main = sortrows(sampleSummary(r.main), "Median");
15+
disp(s.main(:, ["Name", "SampleSize", "Mean", "Median"]))
1316
end
1417

1518

1619
function result = run_bench(name)
1720
suite = testsuite(name);
18-
exp = matlab.perftest.TimeExperiment.limitingSamplingError(MaxSamples=20, RelativeMarginOfError=0.1);
21+
exp = matlab.perftest.TimeExperiment.limitingSamplingError(RelativeMarginOfError=0.1);
1922
result = exp.run(suite);
2023
end

0 commit comments

Comments
 (0)