且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

静态与动态变量 - 速度差

更新时间:2023-09-12 10:55:28

这不是一个性能问题,是否需要在

问题中调用函数之间持续存在的那些变量的

值。如果你这样做 - 使用静态。如果你不 - 使用Dim。

Dennis <德**** @ discussions.microsoft.com>在消息中写道

新闻:9D ********************************** @ microsof t.com ...
我有一个从循环中多次调用的函数。在那个
函数中,我使用三个变量作为计数器和其他用途。我可以使用
DIM来声明变量或静态。使用静态与动态相比,性能会更好吗?我认为使用STATIC
声明会更快,因为变量只需要创建一次。可以
任何人确认这一点。谢谢。
-
丹尼斯在休斯顿



但严格来说,不是静态产生的内存分配代码比

反复呼叫昏暗?


-

Jeff S.

" Scott M. " < S - *** @ nospam.nospam>在消息中写道

news:eh ************** @ TK2MSFTNGP15.phx.gbl ...
这不是在性能问题上,问题是你是否需要在
问题调用函数之间持续存在这些变量的值。如果你这样做 - 使用静态。如果你不 - 使用Dim。

Dennis <德**** @ discussions.microsoft.com>在消息中写道
新闻:9D ********************************** @ microsof t.com。 ..
我有一个从循环中多次调用的函数。在那个
函数中,我使用三个变量作为计数器和其他用途。我可以使用
DIM来声明变量或静态。使用静态与动态相比,性能会更好吗?我认为使用STATIC
声明会更快,因为变量只需要创建一次。可以
任何人确认这一点。谢谢。
-
Dennis in Houston






"丹尼斯" <德**** @ discussions.microsoft.com>写了
我有一个从循环中多次调用的函数。在该函数中,我使用三个变量作为计数器和其他用途。我可以使用
DIM来声明变量或静态。使用静态与动态相比,性能会更好吗?我认为使用STATIC
声明会更快,因为变量只需要创建一次。可以
任何人确认这一点。谢谢。



不要再猜测编译器了。根据需要创建和使用变量

(最小范围)并让编译器决定如何优化它们的使用。


LFS


I have a function which is called from a loop many times. In that function,
I use three variables as counters and for other purposes. I can either use
DIM for declaring the variables or Static. Would the performance be better
using Static versus Dynamic. I would think it would be quicker with STATIC
declarations since the variables would only have to be created once. Can
anyone confirm this. Thanks.
--
Dennis in Houston

It''s not a matter of performance, it''s a matter of whether you need the
values of those variables persisted between calls to the function in
question. If you do - use static. If you don''t - use Dim.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
I have a function which is called from a loop many times. In that
function,
I use three variables as counters and for other purposes. I can either
use
DIM for declaring the variables or Static. Would the performance be
better
using Static versus Dynamic. I would think it would be quicker with
STATIC
declarations since the variables would only have to be created once. Can
anyone confirm this. Thanks.
--
Dennis in Houston



But strictly speaking, won''t static produce less memory allocation code than
repeated calls to dim?

--
Jeff S.
"Scott M." <s-***@nospam.nospam> wrote in message
news:eh**************@TK2MSFTNGP15.phx.gbl...
It''s not a matter of performance, it''s a matter of whether you need the
values of those variables persisted between calls to the function in
question. If you do - use static. If you don''t - use Dim.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
I have a function which is called from a loop many times. In that
function,
I use three variables as counters and for other purposes. I can either
use
DIM for declaring the variables or Static. Would the performance be
better
using Static versus Dynamic. I would think it would be quicker with
STATIC
declarations since the variables would only have to be created once. Can
anyone confirm this. Thanks.
--
Dennis in Houston





"Dennis" <De****@discussions.microsoft.com> wrote
I have a function which is called from a loop many times. In that function,
I use three variables as counters and for other purposes. I can either use
DIM for declaring the variables or Static. Would the performance be better
using Static versus Dynamic. I would think it would be quicker with STATIC
declarations since the variables would only have to be created once. Can
anyone confirm this. Thanks.


Don''t ry to second guess the compiler. Create and use variables as you need them
(least scope) and let the compiler decide how to optimize their use.

LFS