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/find_hotspots.m
View on GitHubfunction hot = find_hotspots(stacks, topN)
%FIND_HOTSPOTS Return the top-N self-time hotspots as data (not printed).
%
% hot = find_hotspots(stacks) % top 20
% hot = find_hotspots(stacks, 10) % top 10
%
% Use this when a script or program needs to act on hotspots programmatically
% (e.g. decide which function to optimize) rather than read a printed report. For
% a human-readable terminal report use print_hotspot_report instead.
%
% INPUT
% stacks : the struct returned by sampling_profiler('off')
% / ('data'), or
% results.stacks from profile_function / profile_test.
% topN : how many hotspots to return (default 20).
%
% OUTPUT
% hot : struct array, sorted by self-samples descending, with fields:
% .location '<file>:<line>' (self/leaf location — where CPU actually is)
% .file file base name (no path/ext)
% .line source line
% .samples leaf-sample count at this location
% .selfPct percent of captured snapshots whose leaf is here
%
% NOTE: self-time = leaf frame of each snapshot. A hot builtin (sort/fft) shows
% as self-time on its CALLING line (builtins have no MATLAB frame of their own).
if nargin < 2 || isempty(topN), topN = 20; end
if ~isfield(stacks, 'Snapshots') || isempty(stacks.Snapshots)
hot = struct('location', {}, 'file', {}, 'line', {}, 'samples', {}, 'selfPct', {});
return;
end
snaps = stacks.Snapshots;
n = numel(snaps);
counts = containers.Map('KeyType', 'char', 'ValueType', 'double');
for s = 1:n
fr = snaps(s).Frames;
d = min(double(snaps(s).Depth), numel(fr));
if d < 1, continue; end
leaf = fr(d); % innermost frame = self-time
[~, b] = fileparts(leaf.FileName);
key = sprintf('%s:%d', b, leaf.StartLine);
if isKey(counts, key), counts(key) = counts(key) + 1; else, counts(key) = 1; end
end
keys = counts.keys;
vals = cell2mat(counts.values);
[vals, ord] = sort(vals, 'descend');
keys = keys(ord);
m = min(topN, numel(keys));
hot = struct('location', {}, 'file', {}, 'line', {}, 'samples', {}, 'selfPct', {});
for i = 1:m
parts = strsplit(keys{i}, ':');
hot(i).location = keys{i}; %#ok<AGROW>
hot(i).file = parts{1};
hot(i).line = str2double(parts{end});
hot(i).samples = vals(i);
hot(i).selfPct = 100 * vals(i) / n;
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: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | 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: 197k | Updated | Claude CodeCodex | Verified | Install |