When passing objects as parameters, are they passed by reference?

后端 未结 5 614
名媛妹妹
名媛妹妹 2021-01-12 12:01

Is there any performance implications if I do either of these:

def do_something(user, article)
...
end

versus

def do_someth         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 12:32

    Yes

    Both method calls will take about the same amount of time.

    (It's good to be aware of performance consequences and you asked a reasonable question, but even so, the standard disclaimer1 about early optimization technically applies.)


    1. First, make program work. Then, profile. Finally, and maybe, optimize.
    Donald Knuth said: We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

提交回复
热议问题