matlab/matlab-agentic-toolkit / skills-catalog/matlab-software-development/matlab-optimize-performance
matlab-optimize-performance
UnverifiedUse when MATLAB code is too slow or the user wants it faster, or asks to profile it, find its hot line or where the time goes, count how many times a function runs, or benchmark or compare timings. Profiles before changing code (Sampling Profiler on R2026b+), checks the output against the original, and reports only measured speedups. Not for writing performance tests.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 13.0 KB |
| assets/measurement-templates.md | markdown | 1.9 KB |
| manifest.yaml | config | 554 B |
| references/measurement-protocol.md | markdown | 14.7 KB |
| references/optimization-patterns.md | markdown | 7.4 KB |
| references/sampling-profiler.md | markdown | 11.1 KB |
| scripts/annotate_source_lines.m | other | 3.9 KB |
| scripts/assertSamplingProfiler.m | other | 913 B |
| scripts/compare_profiles.m | other | 9.0 KB |
| scripts/filter_test_frames.m | other | 2.3 KB |
| scripts/find_hotspots.m | other | 2.5 KB |
| scripts/make_ab_commands.m | other | 4.2 KB |
| scripts/print_hotspot_report.m | other | 3.9 KB |
| scripts/profile_function.m | other | 4.4 KB |
| scripts/profile_script.m | other | 2.7 KB |
| scripts/profile_test.m | other | 5.4 KB |
| scripts/quick_profile.m | other | 2.6 KB |
| scripts/sampling_profiler.p | binary | 587 B |
scripts/quick_profile.m
View on GitHubfunction [stacks, hot] = quick_profile(fn, topN)
%QUICK_PROFILE Profile an expression and print its top hotspots — the fast path.
%
% quick_profile(@() myCode(args)) % capture + print top 15
% quick_profile(@myBenchmark, 20) % top 20
% [stacks, hot] = quick_profile(@() sim(m)) % also return data
%
% The minimal "just show me where the time goes" helper. It runs the correct
% warm-start capture sequence for you:
% on -> pause -> warm-up -> clear -> resume -> measured run -> off -> destroy,
% then prints a hotspot report. For a rigorous timed/baselined run or to save
% results, use profile_function instead.
%
% INPUT
% fn : a function handle, e.g. @() myCode(args). Cannot be @()run('s.m')
% (MATLAB static-workspace rule) — use profile_script for a script.
% topN : hotspots to print (default 15).
%
% OUTPUT (optional)
% stacks : raw stacks struct from the profiled run.
% hot : top-N hotspots as data (see find_hotspots).
if nargin < 2 || isempty(topN), topN = 15; end
assertSamplingProfiler(); % clear error + fallback hint on pre-R2026b
% Warm-start protocol: start the profiler, PAUSE, run the warm-up (its
% first-call cost is not collected), CLEAR, RESUME, then the measured pass.
% Warming up after 'on' rather than before it leaves less first-call cost in
% the measured run.
sampling_profiler('on');
cleanup = onCleanup(@() safeDestroy()); % always tear down, even on error
sampling_profiler('pause');
fn(); % warm-up (not collected)
sampling_profiler('clear');
sampling_profiler('resume');
fn(); % measured run
[~, stacks] = sampling_profiler('off');
clear cleanup; % onCleanup -> safeDestroy() tears down now
fprintf('quick_profile: %d samples (%.2fs implied)\n', ...
stacks.TotalSamples, stacks.TotalSamples/100);
if stacks.TotalSamples < 20
warning('quick_profile:fewSamples', ...
'Only %d samples — result is statistically noisy. Run a longer/heavier workload.', ...
stacks.TotalSamples);
end
print_hotspot_report(stacks, topN);
if nargout > 1, hot = find_hotspots(stacks, topN); end
if nargout == 0, clear stacks; end % called for the printed report only: don't echo the struct
end
function safeDestroy()
try
st = sampling_profiler('status');
if ~strcmp(st, 'off'), sampling_profiler('off'); end
catch
end
try, sampling_profiler('destroy'); catch, end
end
% Copyright 2026 The MathWorks, Inc.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 318k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 318k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 318k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |