Does using Functions make your code run faster?
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all. I'm new in coding in general and in Matlab. I've made some sort of modified capacitated k-means clusterring that clusters more than 30,000 points of data into groups with similar features.
I've done this using only scripts and NOT a single function. Currently, 100 iterations takes about 1hr to complete. I intend to do more than 100 iterations and I intend to add more data points. I'm trying to find ways on how to make this run faster. This said, does converting most of the instructions in the code into functions make it run faster?
From what I've understand so far, scripts save variables in the current workspace while functions does not. But I fail to understand how can this ever matter in terms of the speed of the code implementation provided that in both scenario, data is stored and retrieved from memory. I'm not a data scientist of any kind. Could someone explain how this works?
P.S. I have a Ryzen 5 3550h processor and a 5.9gb usable RAM if computer specs matters.
Any help is greatly appreciated. Thank you.
0 Kommentare
Antworten (1)
Bruno Luong
am 8 Dez. 2020
Bearbeitet: Bruno Luong
am 8 Dez. 2020
MATLAB makes optimization when the code is in function, it does not in script (why it's also mysterious to me, there might be the reason but folks in MATLAB never bother to explain to the end users).
Whereas it matters depending on your code, how much CPU calculation from your script itself or functions that are called by your script.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Cluster Analysis and Anomaly Detection finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!