“MATLAB is slow – if you want to do some serious computation you need to use a proper compiled language like C++.”
Chances are, you’ve come across this kind of opinion while deciding what programming language to use on an upcoming project. But is it really true? Do we have to abandon the comfort of the MATLAB desktop environment, dive into the world of pointers and manual memory allocation, and finally figure out what the difference between dynamic and static linking is? Don’t panic – MATLAB can be plenty fast!
In May, Research IT hosted a workshop led by Mike Croucher, a MathWorks Community Developer Advocate, which was focussed on speeding up MATLAB code. Taking as an example calculating pi to 7 decimal places using Monte Carlo integration, Mike showed how to transform your MATLAB code from sluggish to lightning-fast.
Starting with simple code tweaks to improve performance, Mike then explored how choosing the right algorithm can make a significant difference. Moving beyond basic refactoring, he showed how to parallelise code using your laptop’s CPU. He then took things further by running the same code on a GPU, and eventually across multiple GPUs.
The result? A calculation that originally took over 80 days was reduced to just 4.3 minutes—a staggering 26,600× speed-up. Not bad for an afternoon’s work!
The workshop drew strong interest from researchers across the University, many of whom found it both insightful and inspiring.
“Really enjoyed the course delivered by Mike. Excellent tips and tricks to apply to my own MATLAB code to speed it up!”
"The workshop helped me gain a much better understanding of HPC and how to enhance my original code. I believe many of the tips Mike shared are applicable to other programming languages as well.”
We hope to invite Mike back again in the coming months to share his expertise and further inspire the research community to write blazingly fast MATLAB code. If you'd like to be informed followed us on Bluesky, subscribe to our newsletter or join the CaDiR community.
If you’re interested in getting started with MATLAB, Research IT run an Introduction to MATLAB course 4 times a year. If you’ve got a knotty problem with some MATLAB code you’ve written you can get in touch with our App Support team for assistance via Connect, or come along to one of our regular Drop-In sessions to talk it through.