方法如何提供更好的性能 [英] How does a method give better performance

查看:95
本文介绍了方法如何提供更好的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个场景,我必须为两个inpout参数(1和0)一个接一个地调用所有相同逻辑两次的相同方法。



所以最好写成



如果(x = 1)

通话方式()

elseif(x = 0)

通话方式()



或写两种不同的方法将提供更好的表现



公共功能方法(1)



公共职能方法(2)

Hi,

I have a scenario where i have to call same method with all same logic twice for two inpout parameters (1 and 0) individually one after another .

So is it better to write as

If ( x=1)
Call method()
elseif (x =0 )
Call Method()

or writing two separate methods will be provide better performance

public Function Method(1)

Public Function Method(2)

推荐答案

简单地说,如果您的方法不需要输入参数,则保持原样。我认为拆分它没有性能提升。
Simply stated, if your method does not need the input parameter then leave it as it stands. I see no performance gain in splitting it.


最好使用最适合您需求的方法。因为它不会修改性能。
It's better to use the method that best suits your needs. since it does not modify the performance.


方法用于减少重复代码。如果你没有返回任何东西使用Sub,你在我的脑海中使用了一个Function而不是一个Sub。
Methods are used for decreasing repetitive code. You used a Function instead of a Sub in my mind if your not returning anything use a Sub.


这篇关于方法如何提供更好的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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