静态与动态变量 - 速度差 [英] Static vs Dynamic Variables - Speed Difference

查看:86
本文介绍了静态与动态变量 - 速度差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从循环中多次调用的函数。在该函数中,

我使用三个变量作为计数器和其他用途。我可以使用

DIM来声明变量或静态。性能是否会更好

使用静态与动态。我认为使用STATIC

声明会更快,因为变量只需要创建一次。可以

任何人确认这一点。谢谢。

-

丹尼斯在休斯顿

解决方案

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

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

值。如果你这样做 - 使用静态。如果你不 - 使用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


这篇关于静态与动态变量 - 速度差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆