SPEEDTESTER: quick code speed test and comparison
This small utility function often comes in handy for me, so I thought I'd share it in hopes someone else finds it useful.
SPEEDTESTER(f1,f2,f3,...) evaluates f() for function handle inputs or run(f) if input is a string and displays how long each evaluation took.
SPEEDTESTER(n,f1,f2,f3,...) evaluates each input n times and returns the total time for n evaluations of each.
SPEEDTESTER(n,p,f1,f2,f3,...) displays times to p decimal places.
t = SPEEDTESTER(f1,f2,...) returns time outputs in a vector.
Example included in help: Compare speeds for MAGIC function.
for i = 1:6; inputArgs{i} = sprintf('magic(%i)',100*i); end
inputArgs{2} = @() magic(200);
T = SPEEDTESTER(100,inputArgs{:});
plot(100:100:600,T*10,'o-k')
title('magic(x)'); xlabel('x'); ylabel('Mean eval time (ms)')
Cite As
Sky Sartorius (2026). SPEEDTESTER: quick code speed test and comparison (https://uk.mathworks.com/matlabcentral/fileexchange/43250-speedtester-quick-code-speed-test-and-comparison), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
