Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/matlab-software-development/matlab-write-performance-tests

matlab-write-performance-tests

Verified

Writes MATLAB performance tests using the matlab.perftest.TestCase framework. Use when asked to write, create, or add performance tests for MATLAB code, benchmark functions, measure execution time with statistical rigor, or use runperf.

references/simulink-template.md

View on GitHub
# Simulink Model Performance Test Template

Use this template when benchmarking Simulink model operations (load, compile, simulate).

```matlab
classdef ModelPerformanceTest < matlab.perftest.TestCase
%ModelPerformanceTest Performance test for Simulink model
%   Tests model load and simulation phases.
%
%   Run with: results = runperf('ModelPerformanceTest');

    properties (TestParameter)
        ModelName = {'myModel_small', 'myModel_large'}
    end

    properties
        loadedModel
    end

    methods (TestMethodTeardown)
        function cleanupModel(testCase) %#ok<MANU>
            bdclose('all');
        end
    end

    methods (Test)
        function testModelLoad(testCase, ModelName)
            testCase.startMeasuring();
            load_system(ModelName);
            testCase.stopMeasuring();

            testCase.verifyTrue(bdIsLoaded(ModelName));
        end

        function testModelSimulation(testCase, ModelName)
            % Load outside measurement
            load_system(ModelName);

            testCase.startMeasuring();
            sim(ModelName);
            testCase.stopMeasuring();
        end
    end
end
```

## Notes

- Use `startMeasuring`/`stopMeasuring` to isolate specific phases (load vs compile vs simulate)
- Model load should be measured separately from simulation
- Close models in `TestMethodTeardown` to avoid state leakage between tests
- For meaningful results, ensure the phase of interest runs for at least a few seconds

Copyright 2026 The MathWorks, Inc.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 321kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 321kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 321kUpdated Claude CodeCodexVerifiedInstall
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: 197kUpdated Claude CodeCodexVerifiedInstall