Mid() 与 Mid$() [英] Mid() vs Mid$()
问题描述
根据 VB6 中的文档,Mid() 函数返回一个变体,但 Mid$() 返回一个字符串,显然这更有效.
According to the documentation in VB6 the Mid() function returns a variant, but Mid$() returns a string and apparently this is more efficient.
我的问题是:
我可以使用什么简单的测试来辨别性能差异?我尝试使用 Perfmon,但没有明显的差异.
What simple test can I use to discern the difference in performance ? I tried monitoring a simple app performing a few string operations with Perfmon, but there was no discernible difference.
值得担心吗?我已经养成了使用 $-ized 函数的习惯,但我应该推荐我团队中的每个人也使用它吗?
Is it worth worrying about? I've gotten into the habit of using the $-ized functions, but should I recommend everybody on my team to use it as well?
推荐答案
不值得担心.这是 15 到 20 年前 Microsoft Basic 的残余,当时快速处理器比今天的任何处理器都慢几个数量级.
Isn't worth worrying about. It's a remnant from Microsoft Basic of 15-20 years ago when a fast processor was orders of magnitude slower than anything today.
尽管如此,使用 Mid$ 而不是让 VB 确定您的数据类型具有一定的审美吸引力.如果您有任何循环正在执行它,例如每秒执行数千次,那么您的好奇心可能会增加.否则,不.
It has a certain esthetic appeal to use Mid$ rather than let VB determine what your datatypes are, though. And if you have any loops that are executing it, say, thousands of tiems a second, then your curiosity factor might increase. Otherwise, neh.
这是一个链接,指向测量差异的人.Mid$ 的速度大约是 Mid 的 2.5 倍.包括回到 VB4 的测试.
Here's a link to someone who measured the difference. Mid$ was about 2.5 times as fast as Mid. Including tests going back to VB4.
这篇关于Mid() 与 Mid$()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!