在VBA/QTP中字符串比较是如何工作的?是否内置了高效的字符串哈希函数?

发布于 2024-10-11 22:47:37 字数 340 浏览 12 评论 0原文

我需要比较 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

似狗非友 2024-10-18 22:47:37

在任何理智的语言中,字符串比较都以线性时间运行。哈希算法不会提高字符串比较速度,除非字符串很少更新,并且在更新时进行哈希处理(而不是在比较之前进行哈希处理)。这需要修改您的应用程序以包含字符串结构及其关联的哈希值。

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.

软糯酥胸 2024-10-18 22:47:37

看起来没有任何优化(明显的优化是检查字符串是否相同长度),但是当比较 1,000,000 个字符字符串时,它需要不到 0.1 秒,所以我认为你不应该担心 100K 字符字符串。

这是我测试的方法。

base = String(1000000, "x")
first = base & "a"
sameLength = base & "b"
differentLength = base & "cd"

MercuryTimers.Timer("x").Start
diff = first <> sameLength
print "sameLength = " & diff & " after " & MercuryTimers.Timer("x").ElapsedTime
MercuryTimers.Timer("x").Reset

MercuryTimers.Timer("x").Start
diff = first <> differentLength
print "differentLength = " & diff & " after " & MercuryTimers.Timer("x").ElapsedTime
MercuryTimers.Timer("x").Reset

定时输出大致相同,这是典型的输出(时间以毫秒为单位)

sameLength = 40 后为 True
differentLength = 30 后为 True

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.

base = String(1000000, "x")
first = base & "a"
sameLength = base & "b"
differentLength = base & "cd"

MercuryTimers.Timer("x").Start
diff = first <> sameLength
print "sameLength = " & diff & " after " & MercuryTimers.Timer("x").ElapsedTime
MercuryTimers.Timer("x").Reset

MercuryTimers.Timer("x").Start
diff = first <> differentLength
print "differentLength = " & diff & " after " & MercuryTimers.Timer("x").ElapsedTime
MercuryTimers.Timer("x").Reset

The timed outputs were about the same, here's a typical output (time is in milliseconds)

sameLength = True after 40
differentLength = True after 30

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文