pusofalse 发表于 2011-4-15 07:38:45

回复 30# gto250


返回值是一个2进制串。字节0xFF 表示两个字符串中,相对应的4个字符是相同的。字节0x00表示相对应的4个字符不同。29#的代码,比较字符串"Text1"、"Text2"返回的结果会是0xFF00。返回的2进制字符串的长度是ceiling(maxlength(string1, string2) / 4)。

pusofalse 发表于 2011-4-15 07:48:28

回复 30# gto250


    循环1次,现在已经改为循环500次了。

shenrenba 发表于 2011-4-15 09:40:28

全部单次对比超出部分赋值为0   不知道我理解的对不 0.013 作用

3mile 发表于 2011-4-15 14:30:35

回复 28# love5173
$begin = TimerInit()
$a="1111123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430123456789012345698765432107654301234567890123456987654321076543012345678901234569876543210765430"
$b="8100213495412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123580125789685469870125493159541235801257896854698701254931595412358012578968546987012549315954123"
Local $Array_A=StringRegExp(StringUpper($a),'.{4}',3)
Local $Array_B=StringRegExp(StringUpper($b),'.{4}',3)
local $c

for $i =0 to UBound($Array_A)-1
      $Array_A[$i]=cover($Array_A[$i])
      $Array_B[$i]=cover($Array_B[$i])
Next

For $n=1 To 500
      for $i=0 to UBound($Array_A)-1
                        $c&=$Array_A[$i]=$Array_B[$i]
      Next
$dif = TimerDiff($begin)
Next
MsgBox(0,$dif/1000,$c)

func cover($string)
      local $number
      for $k=1 to 4
                $number&=Asc(StringMid($string,$k,1))
      Next
      return Execute($number)
EndFunc

love5173 发表于 2011-4-15 16:54:45

回复 34# 3mile
本来我要说,把乘权值改成 任意数的幂的形式就可以用加了,最简单的数自然是2了
我也没找到2的$k次方怎么写,汗颜,帮助我看了 确实没找到

gto250 发表于 2011-4-15 20:35:24

回复 33# shenrenba
字符串a和b永远都是一样的长度的

gto250 发表于 2011-4-15 20:49:27

回复 31# pusofalse
P版的代码是效率最高的,但是不方便修改呀,如果要改成下列要求的方式,应该怎么改那个代码呢,不吝赐教!!

字符串a和b的长度永远都是一样的,而且长度都是2的倍数,唯一不同的是,
按照需要不同,有时是2个数为一位进行比较,那么字串长度是2的倍数。
有时是4个数为一位进行比较,那么字串长度是4的倍数。
或者是4个数为一位进行比较,那么字串长度是6的倍数。
依次推算
最大的时候是10个数为1位进行比较,那么字串长度是10的倍数。

如:

当设置为2个数为一位的时候进行比较,长度为2的10倍为:
$a=12 34 56 78 90 12 34 56 78 90
$b=12 34 56 78 90 09 87 65 78 21   
返回$c=0 0 0 0 0 1 1 1 1 1

当设置为4个数为一位的时候进行比较,长度为4的5倍为:
$a=6521 5678 9012 3456 8812
$b=6521 5678 9009 8765 7821   
返回$c=0 0 1 1 1

当设置为6个数为一位的时候进行比较,长度为6的3倍为:
$a=123456 789012 345678
$b=123456 789009 876578   
返回$c=0 1 1

当设置为10个数为一位的时候进行比较,长度为10的1倍为:
$a=123456789 01234567890
$b=123456789 00987657821   
返回$c=0 1

gto250 发表于 2011-4-16 10:20:51

回复 35# love5173

2^$k

love5173 发表于 2011-4-16 14:12:02

回复 38# gto250
谢谢,我想如果在效率相差不到1秒的时候,上面算法都可以了吧
3M那个把乘$K改成乘2^$k 就可以了

tryhi 发表于 2011-4-19 18:04:00

本帖最后由 tryhi 于 2011-4-19 18:07 编辑

1G内存、4800+,2.5GHz,双核

我运行1楼的代码居然用了43秒……这是什么机器啊

love5173 发表于 2011-4-19 18:52:53

回复 40# tryhi


    我之前机器也这样,好像是开机太久的原因吧!具体不知道,重启就好了
页: 1 2 [3]
查看完整版本: 字符串比较的效率问题[已解决]