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 |
assets/measurement-templates.md
View on GitHub# Measurement Templates
MATLAB script templates for three measurements. To profile, compare and check correctness, follow Steps 2–6 in SKILL.md.
## Template 1: Baseline Measurement (timeit)
```matlab
% baseline_measure.m
% Measures baseline performance of a target function
% Setup — NOT timed
rng('default');
data = rand(1e6, 1); % adjust to realistic input size
% Define function handle
f = @() targetFunction(data);
% Warmup is handled by timeit automatically
baseline = timeit(f);
fprintf('Baseline: %.6f s\n', baseline);
% Save for later comparison
save('baseline.mat', 'baseline');
```
## Template 2: GPU Timing
```matlab
% gpu_timing.m
% Properly time GPU operations
dev = gpuDevice;
gpuData = gpuArray(rand(1e6, 1));
% Use gputimeit (preferred — handles sync and warmup)
f = @() myGpuFunction(gpuData);
t = gputimeit(f);
fprintf('GPU time (gputimeit): %.6f s\n', t);
% Manual timing (when gputimeit isn't suitable)
% Warmup
for w = 1:5
wait(dev);
myGpuFunction(gpuData);
wait(dev);
end
% Measure
nRuns = 20;
times = zeros(1, nRuns);
for i = 1:nRuns
wait(dev);
tic;
myGpuFunction(gpuData);
wait(dev); % CRITICAL: sync before reading timer
times(i) = toc;
end
fprintf('GPU time (manual): %.6f s (median of %d runs)\n', median(times), nRuns);
```
## Template 3: Scaling Test
```matlab
% scaling_test.m
% Test how performance scales with input size
sizes = [1e3, 1e4, 1e5, 1e6, 1e7];
times = zeros(size(sizes));
for k = 1:numel(sizes)
data = rand(sizes(k), 1);
f = @() targetFunction(data);
times(k) = timeit(f);
end
% Plot scaling behavior
figure;
loglog(sizes, times, '-o', 'LineWidth', 2);
xlabel('Input size (N)');
ylabel('Time (s)');
title('Performance Scaling');
grid on;
% Check scaling order
slopes = diff(log(times)) ./ diff(log(sizes));
fprintf('Estimated scaling exponents: %s\n', mat2str(slopes, 2));
fprintf('(1.0 = linear, 2.0 = quadratic)\n');
```
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: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | 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: 198k | Updated | Claude CodeCodex | Verified | Install |