在VBA/QTP中字符串比较是如何工作的?是否内置了高效的字符串哈希函数?
我需要比较 QTP 中的两个非常大的字符串(我相信是由 vba 派生引擎解释的)。我知道这些字符串将超过 100,000 个字符,并且我需要能够检测到这些大字符串之一何时发生变化。首先,我使用了以下内容:
if prevtext <>那么当前文本 ... 如果
我期待它会爆炸的话就结束了,但实际上脚本运行得相当快。字符串比较期间没有明显的减慢。因此,我怀疑字符串比较实际上是截断了我范围之外的字符串,或者做了其他可能作弊的事情。有谁知道我是否真的可以依靠内置的字符串比较运算符来比较两个 100,000 多个字符串?如果没有,是否有一些本机哈希函数可以替换它?它只需要能够检测变化,而不是变化的内容,并且需要快速运行。
I need to compare two very large strings in QTP (intepreted by a vba-derived engine, I believe). I know these strings will exceed 100,000 characters, and I need to be able to detect when there is a change in one of these large strings. To start off I used the following:
if prevtext <> currenttext then
...
end if
I was expecting this to explode, but actually the script ran quite fast. There was no noticeable slowdown during the string comparison. So, I am suspicious that the string compare is actually truncating the strings outside of my scope or doing something else that would be cheating. Does anyone know if I can actually rely on the built in string comparison operator to compare two 100,000+ character strings? If not is there some native hashing function that I can replace this with? It just needs to be able to detect changes, not the content of the changes, and it needs to run quickly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
VBA 将允许大约 20 亿个字符: http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/a1d8ee65-75e6-4a29-9670-6e233c398642
VBA will allow about 2 billion characters: http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/a1d8ee65-75e6-4a29-9670-6e233c398642
在任何理智的语言中,字符串比较都以线性时间运行。哈希算法不会提高字符串比较速度,除非字符串很少更新,并且在更新时进行哈希处理(而不是在比较之前进行哈希处理)。这需要修改您的应用程序以包含字符串结构及其关联的哈希值。
String compares, in any sane language, run in linear time. A hashing algorithm will not improve the string comparison speed unless the strings are only updated very infrequently and hashed when they are updated (as opposed to hashed before comparison). This would require modifying your application to contain a structure of Strings and their associated hash.
看起来没有任何优化(明显的优化是检查字符串是否相同长度),但是当比较 1,000,000 个字符字符串时,它需要不到 0.1 秒,所以我认为你不应该担心 100K 字符字符串。
这是我测试的方法。
定时输出大致相同,这是典型的输出(时间以毫秒为单位)
It doesn't look like there's any optimization (the obvious optimization would be to check if the strings are the same length) however when comparing 1,000,000 char string it takes less than 0.1 seconds so I don't think you should worry about 100K char strings.
Here's how I tested it.
The timed outputs were about the same, here's a typical output (time is in milliseconds)