When should the performance impact of a function call be considered?

In a recent conversation with another programmer, I argued that "if you write the same code more than once, it is probably a good idea to reorganize this functionality so that it can be called once from each of these places."

My fellow programmer instead insisted that the impact of making these function calls was unacceptable.

Now I'm not looking for confirmation of who was right. I'm just curious to know if there are situations or patterns where I should consider the effect of calling a function before refactoring.

+3
source share
7 answers

" - , ".

... " ."

. , , , .

, , , , 10 , .

+3

, , , , . , , , , .

+2

, Java, . , , . , , - .

+2

:

  • , , .
  • ?
  • ?
  • , ? .

, , ?:)

+1

, , , .

, , -.

, , , .

. , , .

, , . , . , . . , , .

+1

, - : , .

+1

c/++:

"" . , , . , :

  • , .

. :

  • callsite. , ( / ). - , , , .

inline . . () . , . , .

Assuming you are using a modern compiler, there is no excuse to avoid this function if you also do not want to go to the build for this particular program.

since if performance is critical, you really have two options:

1) learn to write well-organized programs for speed. downside: longer compilation time

2) support a poorly written program

I prefer 1. any day.

(yes, I spent a lot of time developing critical programs)

0
source

Source: https://habr.com/ru/post/1792866/


All Articles