Do global variables mean faster code?

后端 未结 14 1981
情深已故
情深已故 2020-12-24 00:58

I read recently, in an article on game programming written in 1996, that using global variables is faster than passing parameters.

Was this ever true, and if so, is

14条回答
  •  孤城傲影
    2020-12-24 01:50

    What do you mean, "faster"?

    I know for a fact, that understanding a program with global variables takes me a whole lot more time than one without.

    If the extra time it takes the programmer(s) is less than the time gained by the users when they run the program with globals, then I'd say using global is faster.

    But consider that the program is going to be run by 10 people once a day for 2 years. And that it takes 2.84632 secs without globals and 2.84217 secs with globals (a 0.00415 sec increase). That's 727 seconds less of TOTAL runtime. Gaining 10 minutes of run time is not worth the introduction of a global as regards programmer time.

提交回复
热议问题