循环变量 - 整数与长整数 [英] Looping variables - Integer vs Long

查看:158
本文介绍了循环变量 - 整数与长整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用循环变量进行了一次测试,首先调整为整数,然后是
然后调整为Long。我发现Integer在循环时更快。我知道这是为了确保在16位的日期里,CPU的(80286)字大小是16

与整数相同。


现在使用32位CPU我会期望长得更快,因为它与CPU的字大小相同,所以不会这么大不需要在

中进行锯切,就像魔术师的助手一样计算就像一个整数一样。

那么为什么整数仍然比一个龙更快? br />

VBA是否仍然卡在16位?

解决方案

奇怪!我会预测多头更快。

你能发布你的循环代码,以便我们可以测试并看到这个奇迹吗?


< blockquote> On Fri,2005年10月28日12:43:07 +0100,Trevor Best< no **** @ localhost.invalid>写道:

我使用循环变量进行了一次测试,首先调整为整数,然后调整为Long。我发现Integer在循环时更快。我知道这是真的,在16位的日子里,CPU的(80286)字大小是一个整数相同的16位。

现在有一个32位CPU我原本期望长得快,因为它的大小与CPU的字大小相同所以不需要像魔术师一样锯切一半''像一个整数一样计算的助手会。
那么为什么整数仍然比一个龙更快呢?

VBA是否仍然卡在16位?





http://groups.google.com.au/group/mi...98955791f1afee

在线程结束时获取一些信息令人兴奋的是,更全面的解释在那里引用

似乎已经消失了。


2005年10月28日星期五12:43:07 +0100,Trevor Best < no **** @ localhost.invalid>

写道:

我使用循环变量进行了一次测试,首先调整为整数,<然后就像龙一样。我发现Integer在循环时更快。我知道这是真的,在16位的日子里,CPU的(80286)字大小是一个整数相同的16位。

现在有一个32位CPU我原本期望长得快,因为它的大小与CPU的字大小相同所以不需要像魔术师一样锯切一半''像一个整数一样计算的助手会。
那么为什么整数仍然比一个龙更快呢?

VBA是否仍然卡在16位?




奇怪的是,我曾经从微软读过一些东西,说明

VBA将字节和整数转换为Long进行处理,所以它更多

有效地定义一切开始的方式。我原以为

很长时间才能提供更好的性能。


I did a test once using a looping variable, first dimmed as Integer,
then as Long. I found the Integer was quicker at looping. I knew this to
be true back in the 16 bit days where the CPU''s (80286) word size was 16
bits same as an integer.

Now with a 32 bit CPU I would have expected the long to be faster as
it''s the same size as the CPU''s word size so wouldn''t need sawing in
half like a magician''s assistant to calculate on like an integer would.
So why is an Integer still faster than a Long?

Is VBA still stuck in 16 bits somewhere?

解决方案

Strange! I would have predicted the longs as faster.
Can you post your looping code so that we can test and see this marvel?


On Fri, 28 Oct 2005 12:43:07 +0100, Trevor Best <no****@localhost.invalid> wrote:

I did a test once using a looping variable, first dimmed as Integer,
then as Long. I found the Integer was quicker at looping. I knew this to
be true back in the 16 bit days where the CPU''s (80286) word size was 16
bits same as an integer.

Now with a 32 bit CPU I would have expected the long to be faster as
it''s the same size as the CPU''s word size so wouldn''t need sawing in
half like a magician''s assistant to calculate on like an integer would.
So why is an Integer still faster than a Long?

Is VBA still stuck in 16 bits somewhere?



see
http://groups.google.com.au/group/mi...98955791f1afee
towards the end of the thread for some information on excodes, the "fuller explanation" cited there
seems to have vanished.


On Fri, 28 Oct 2005 12:43:07 +0100, Trevor Best <no****@localhost.invalid>
wrote:

I did a test once using a looping variable, first dimmed as Integer,
then as Long. I found the Integer was quicker at looping. I knew this to
be true back in the 16 bit days where the CPU''s (80286) word size was 16
bits same as an integer.

Now with a 32 bit CPU I would have expected the long to be faster as
it''s the same size as the CPU''s word size so wouldn''t need sawing in
half like a magician''s assistant to calculate on like an integer would.
So why is an Integer still faster than a Long?

Is VBA still stuck in 16 bits somewhere?



What''s really odd is that I read something from Microsoft once stating that
VBA converts bytes and integers to a Long for processing, so it''s more
efficient to define everything that way to start with. I would have expected
Long to give the better performance.


这篇关于循环变量 - 整数与长整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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