You are all right in the sense that I had not fully baked in my head the ideas before first writing them here. I’ve edited the post with important changes.
Right, I had realized that only after Ist posting ; I’ve corrected now.
Right that the only difference is in duration taken by first- vs subsequent- calls of a function.
I wanted to find out whether I can predict when the difference will be big, that’s why I asked about that “rule of thumb”.
As exemplified in a reply, a function like
function f()
...
# ANY number of assignments with complex arithmetic expressions
# but which can be modeled by a (acyclic) dependency graph
# and don't involve side-effects
...
return(last_variable) # asssume last_variable is bound to a number -type value
end
and one like
function g()
return(100)
end
will take exactly the same amount of time of execution, at all subsequent calls of the function (in a given program or REPL session). While first call of f()
may take much much longer than g()
.