TransWikia.com

A Function of Arguments or a Function of a List of those Arguments – Which is Recommended?

Mathematica Asked by Just Some Old Man on July 26, 2021

Which is recommended from a programming perspective and has better performance in memory and speed given guaranteed identical output – a function taking many arguments and then referring to those arguments directly or a function taking a single list containing those arguments as elements and then referring to those elements using Part[]?

That is, if n is large or f is called many times, which of the following is better to use given the output is the same?

f[x1_,x2_,...,xn_]:=(*body refers to x1,x2,...,xn directly*)

or

f[list_]:=(*body calls list[[1]],list[[2]],...,list[n]*)

For small n, standard practice is to use the former, but I am wondering if things change for very large n.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP