Does the use of name-value arguments in functions slow down the speed of my code?

4 vues (au cours des 30 derniers jours)
The use of name-value arguments in functions allows a much more flexible use of functions. The simple alternative for me would be to write an additional function in order to have two quite similar functions without name-value arguments. Then, I would of course get a lot of duplicates of code if I would do it for my whole program.
However, I was wondering whether it would affect the speed of my program when I change a function to name-value arguments which is called multiple 1000 times?

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Fév 2023
Yes, of course argument processing takes execution time. MATLAB does not somehow cache the results of the argument processing code from execution to execution: it runs it every iteration. Over many iterations that adds up.
However, you need ask yourself whether the cost of those CPU cycles is more than the cost of you developing and maintaining two similar but different functions.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by