Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Feb. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by