而且还有AndAlso,表现? [英] And vs. AndAlso, performance??

查看:80
本文介绍了而且还有AndAlso,表现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇是否有人知道And / AndAlso和

Or / OrElse的组合在性能方面的比较。

这需要更多的系统工作对And

进行两次评估或对AndAlso进行短路?


纯粹是为了启蒙。


提前谢谢。


- Arthur Dent。

解决方案

嗯 - OrElse和AndAlso都是短路运营商。所以对OrElse来说,如果满足第一个条件,那么
,它甚至不会检查第二个条件(

可能是一个冗长的操作)。同样地,对于AndAlso来说,如果没有达到第一个

条件,它就会在没有检查第二个条件的情况下突破。

所以在两个短路操作中,当第一个满足(OrElse)或不满意时,你会节省额外的

条件检查

(AndAlso)。所以这些应该会给你更好的表现。请注意

其正在评估的表达式需要处理时间

而不是运算符本身执行的操作(

简单的布尔运算)。它只是短路运算符b / b运算符评估的方式,它给你提供更好的b / b
性能的概率。

希望有所帮助。 。

Imran。


旅行者 <喜********************* @ yahoo.com>在留言中写道

news:u%**************** @ TK2MSFTNGP10.phx.gbl ...

我是只是好奇,如果有人知道And / AndAlso和
Or / OrElse的组合如何在性能方面进行比较。
这需要更多的系统工作,对And
进行两次评估或执行AndAlso上的短路?

纯粹是为了启蒙。

提前致谢。

- Arthur Dent。


" A Traveller" <喜********************* @ yahoo.com> schrieb:

我很好奇,如果有人知道And /
AndAlso和Or / OrElse的组合在性能方面的比较。
这对系统来说需要更多的工作,和And
进行两次评估或者对AndAlso进行短路?




我更喜欢''AndAlso''/''OrElse''应该进行逻辑操作。

在许多情况下短路更快,因为通常不需要评估部分

表达式。


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>


嗯 - OrElse和AndAlso都是短路运营商。所以对OrElse来说,如果满足第一个条件,那么
,它甚至不会检查第二个条件(

可能是一个冗长的操作)。同样地,对于AndAlso来说,如果没有达到第一个

条件,它就会在没有检查第二个条件的情况下突破。

所以在两个短路操作中,当第一个满足(OrElse)或不满意时,你会节省额外的

条件检查

(AndAlso)。所以这些应该会给你更好的表现。请注意

其正在评估的表达式需要处理时间

而不是运算符本身执行的操作(

简单的布尔运算)。它只是短路运算符b / b运算符评估的方式,它给你提供更好的b / b
性能的概率。

希望有所帮助。 。

Imran。


旅行者 <喜********************* @ yahoo.com>在留言中写道

news:u%**************** @ TK2MSFTNGP10.phx.gbl ...

我是只是好奇,如果有人知道And / AndAlso和
Or / OrElse的组合如何在性能方面进行比较。
这需要更多的系统工作,对And
进行两次评估或执行AndAlso上的短路?

纯粹是为了启蒙。

提前致谢。

- Arthur Dent。


I was just curious if anyone knows how the combinations of And/AndAlso and
Or/OrElse compare in terms of performance.
Which takes more work for the system, performing two evaluations on an And
or performing short-circuiting on an AndAlso?

Purely for enlightenment.

Thanks in advance.

- Arthur Dent.

解决方案

Well - both OrElse and AndAlso are short circuit operators. So for OrElse,
if the first condition is met, it won''t even check the second one (which
could be a lengthy operation). Similarly, for AndAlso, if the first
condition is not met, it''ll break out without even checking the second one.
So in both the short circuit operations, you''re saving on the extra
condition check when the first one is satisfied (OrElse) or not satisfied
(AndAlso). So these should give you better performance in general. Note that
its the expressions that are being evaluated that take the processing time
and not the operations performed by the operators themselves (which are
simply boolean operations). Its just the way in which the short-circuit
operators evaluate which gives you a higher probability of better
performance.
hope that helps..
Imran.

"A Traveler" <hi*********************@yahoo.com> wrote in message
news:u%****************@TK2MSFTNGP10.phx.gbl...

I was just curious if anyone knows how the combinations of And/AndAlso and
Or/OrElse compare in terms of performance.
Which takes more work for the system, performing two evaluations on an And
or performing short-circuiting on an AndAlso?

Purely for enlightenment.

Thanks in advance.

- Arthur Dent.



"A Traveler" <hi*********************@yahoo.com> schrieb:

I was just curious if anyone knows how the combinations of And/
AndAlso and Or/OrElse compare in terms of performance.
Which takes more work for the system, performing two evaluations on an And
or performing short-circuiting on an AndAlso?



I would prefer ''AndAlso''/''OrElse'' when a logical operation should be done.
Short circuiting is faster in many cases, because often parts of the
expression don''t need to be evaluated.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Well - both OrElse and AndAlso are short circuit operators. So for OrElse,
if the first condition is met, it won''t even check the second one (which
could be a lengthy operation). Similarly, for AndAlso, if the first
condition is not met, it''ll break out without even checking the second one.
So in both the short circuit operations, you''re saving on the extra
condition check when the first one is satisfied (OrElse) or not satisfied
(AndAlso). So these should give you better performance in general. Note that
its the expressions that are being evaluated that take the processing time
and not the operations performed by the operators themselves (which are
simply boolean operations). Its just the way in which the short-circuit
operators evaluate which gives you a higher probability of better
performance.
hope that helps..
Imran.

"A Traveler" <hi*********************@yahoo.com> wrote in message
news:u%****************@TK2MSFTNGP10.phx.gbl...

I was just curious if anyone knows how the combinations of And/AndAlso and
Or/OrElse compare in terms of performance.
Which takes more work for the system, performing two evaluations on an And
or performing short-circuiting on an AndAlso?

Purely for enlightenment.

Thanks in advance.

- Arthur Dent.



这篇关于而且还有AndAlso,表现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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