关于在字符串中搜索的测试我向Jay B承诺 [英] A test about searching in a String I promised Jay B.

查看:47
本文介绍了关于在字符串中搜索的测试我向Jay B承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我昨天答应Jay B做一些测试。


这个主题是Jon发送的字符串评估杰伊B对此表示怀疑

更好的是因为C#newsgroup在9月25日的b
讨论过。新闻组中涉及的正则表达式。


我昨天晚上告诉Jay,我会测试所有4种方法和

愚蠢的方法我是想起那天晚上第一次看到Jon'的
代码。 Herfried从那里说,用一串10亿美元的b / b来减慢它会变慢。所以我告诉Herfried我会制作测试程序,如果他为我输入一个真正的混合字符串中的

。但直到现在他还没发送。 (或者也许

他再次遇到新闻组服务器的问题)


对Jay BI也告诉我,我会尝试额外测试

Microsoft.visual基本函数Instr和系统函数indexof。


我测试的方法是:

- 一个直到方法指数(周杰伦B)

- 与Instr(Jon)一起做的方法

- 我改变了一些东西到indexof(Jon)

这些都是用字符串工作

其他只有字符作为搜索项目

- 一个愚蠢的方法,只需要2行代码,这就是我想法中的内容

昨天晚上

- 一个带有char的索引(Jay B)

- 每个带有一个char(Jay B)

我制作了一个测试程序,我将此信息发送到下面。

因为所有信息都依赖于您使用的计算机,如果您愿意,我不会给出绝对的

数字你可以自己试试。在我的电脑上,使用任何方法看到差异超过1/1000秒与

字符串短于5000个字符是不可能的


超过那个数量的字符,我想到的愚蠢的方法昨天变得更慢了。


当它是真正的长字符串时,与我的测试相比,在我的测试中,最快的方法是为循环做。与indexof第二个是每个

char来自Jay B.


但对我来说最令人惊讶的是Microsoft.visualbasic函数

withInstr使用3字符串

时,Jon的速度比net.system方法indexoff快2倍。


我在下面执行测试程序;它是用windowsform项目制作的,并且

需要2个文本框,textbox1需要多行真,一个

button1和一个大标签。


Texbox1是用于制作字符串的文本(自动制作直到

Herfried发送给他)。

Textbox2文本字符串的长度制作(是的,你了解它

直到....)


我希望这能给出一些想法(也是有些人说的

microsoft.visualbasic函数速度慢且过时,这个你可以用
当然不用C#测试。)

Cor

\\\

Private Sub Button1_Click(ByVal sender _

As Object,ByVal e As System.EventArgs)处理Button1.Click

如果Me.TextBox1.Text =""然后

Me.label1.Text ="在uper文本框中输入字符串"

退出Sub

结束如果

如果不是IsNumeric(Me.TextBox2.Text)那么

Me.label1.Text ="在下方文本框中输入值

退出Sub

结束如果

TestString.Build(Me.TextBox1.Text.ToString,CInt(Me.TextBox2.Text))

Dim delimiter As String

如果TestString.StringToTest.Length> 3然后

delimiter = TestString.StringToTest.Substring(0,3)

Else

退出Sub

结束如果

Dim i As Integer

Dim labeltext As New System.Text.StringBuilder

Dim count As Integer

Dim testname As String

For i = 1 To 3

Dim StartTick As Integer = Environment.TickCount

Select Case i

案例1

testname =" Jay B,string"

count = Test1(TestString.StringToTest,delimiter)

案例2

testname =" Jon,string"

count = Test2(TestString.StringToTest,delimiter)

案例3

testname =" Jon,但是indexof"

count = Test3(TestString.StringToTest,delimiter)

结束选择

Dim Elapsed As Integer = Environment.TickCount - StartTick

labeltext.Append(testname&" count:"& _

count&" Elapsed:" ;& Elapsed。 ToString& vbCrLf)

下一页

delimiter = delimiter.Substring(0,1)

labeltext.Append(" characters"& vbCrLf)

对于i = 1到6

Dim StartTick As Integer = Environment.TickCount

选择案例i

案例1

testname =" Jay B,string"

count = Test1(TestString.StringToTest,delimiter)

案例2

testname =" Jon,string"

count = Test2(TestString.StringToTest,delimiter)

案例3

testname =" Jon,但是indexof"

count = Test3(TestString.StringToTest,delimiter)

案例4

如果TestString.StringToTest .Length< 599999然后

testname =" Cor stupid"

count = Test4(TestString.StringToTest,delimiter)

Else

testname =" Skipped test"

结束如果

案例5

testname =" Jay B char do until

count = test5(TestString.StringToTest,delimiter)

案例6

testname =" Jay B char for each"

count = test6(TestString.StringToTest,delimiter)

结束选择

Dim Elapsed As Integer = Environment.TickCount - StartTick

labeltext.Append(testname&" count:"& _

count&" Elapsed:"& Elapsed.ToString& vbCrLf)

下一页

Me.label1.Text = labeltext.ToString

End Sub

Private Sub Form1_Load(ByVal sender As Object,ByVal _
$ b $ as As System.EventArgs)Handles MyBase.Load

Me.Button1.Text =" start test"

End Sub
公共函数Test1(ByVal输入为字符串,ByVal分隔符_

字符串)As Integer''Jay B 1(字符串)

Dim count,index As整数

index = input.IndexOf(分隔符)

Do Until index< 0

count + = 1

index = input.IndexOf(分隔符,索引+ 1)

循环

返回计数

结束函数

公共函数Test2(ByVal strInput As String,ByVal strDelimiter _

As String)As Int32''Jon(string )

Dim iStart As Int32,iCount As Int32,iResult As Int32

iStart = 1

iCount = 0



iResult = InStr(iStart,strInput,strDelimiter)

如果iResult = 0则退出Do

iCount + = 1
iStart = iResult + 1

循环

返回iCount

结束功能

公共功能测试3 (ByVal输入As String,ByVal delimiter _

As String)As Integer''Jon with indexof(x,x,x)

Dim iStart As Int32,iCount As Int32 ,iResult作为Int32

iStart = 0

iCount = 0



iResult = input.IndexOf(delimiter) ,iStart)

如果iResult = -1则退出Do

iCount + = 1

iStart = iResult + 1

循环

返回iCount

结束功能

公共功能测试4(ByVal输入As String,ByVal分隔符_

As String)As Integer''Cor stupid

Dim teststring As String()= Split(input,delimiter)

返回teststringtring.Length - 1

结束函数

公共函数test5(ByVal输入为字符串,ByVal _

分隔符为Char)作为整数''杰伊1(char)

昏暗计数,索引为整数

index = input.IndexOf(分隔符)

Do Until index < 0

count + = 1

index = input.IndexOf(分隔符,索引+ 1)

循环

返回计数

结束函数

公共共享函数test6(ByVal输入为字符串,_

ByVal分隔符为Char)作为整数''JayB 2 (char)

Dim count As Integer

For each ch As Char In输入

如果ch =分隔符那么

计数+ = 1

结束如果

下一页ch

返回计数

结束功能

结束类

公共类TestString

私有共享mStringTest作为字符串

公共共享ReadOnly属性StringToTest()As String

获取

返回mStringTest

结束获取

结束财产

公共共享子构建(ByVal strToTest作为String,ByVal x As Integer)

Dim strTest As New System.Text.StringBuilder

Dim strTextbox As String()= Split(strToTest,vbCrLf)

Do strTest.ToString.Length< x

Dim i As Integer

For i = 0 to strTextbox.Length - 1

Dim y As Integer

对于y = 0到i

如果strTest.ToString.Length< x / 2然后

strTest.Append(strTest.ToString& strTextbox(i))

Else

strTest.Append(strTest.ToString .Substring(0,x / 2)_

& strTextbox(i))

结束如果


下一页

下一页

循环

mStringTest = strTest.ToString.Substring(0,x)

End Sub

结束班

///

解决方案

你好Cor,


|| Herfried从那里说,它会变得很慢

||用10Mb的字符串。所以我告诉Herfried我

||如果他输入一个

||,我会做测试程序真正的混合字符串给我。但直到现在他还没发送

||那。 (或许他再次遇到问题

||新闻组服务器)


我刚刚在医院与Herfried说话 - 它''不看好了

好​​。在疼痛难以忍受之前,他得到了角色432764。

医生已经诊断出他们在b
年中看到的最严重的RSI病例。当Herfried输入的速度和他能够及时获得的时间一样快,并不奇怪。不幸的是,截肢可能是最合理的结果。

: - ((


问候,

Fergus


" Fergus Cooney"< fi ****** @ tesco.net> scripsit:

Herfried从那说,用10Mb的字符串会变得很慢。所以我告诉Herfried我



我告诉它会消耗很多内存,但我从来没有说过

的表现会很差。

我刚刚在医院跟Herfried说话了 - 这看起来不太好。他得到了在疼痛难以承受之前,人物已经确定了最严重的RSI病例,即b $ b

什么是RSI?

他们多年来见过。当Herfried打字的速度尽可能快到你能及时获得文件时就不足为奇了。
不幸的是截肢可能是最合理的来了。
: - ((




: - (


-

Herfried K. Wagner

MVP·VB Classic,VB.NET

< http://www.mvps.org/dotnet>


Hi Herfried,


重复性紧张伤害 - 你输入太多太长时间得到的东西。

怎么样?现在的手腕 - 医生仍然认为手必须来吗

关闭? ;-)


问候,

Fergus


Hallo,

I have promised Jay B yesterday to do some tests.

The subject was a string evaluation that Jon had send in. Jay B was in doubt
what was better because there was a discussion in the C# newsgroup on 25
September. The regular expressions where in that newsgroup too involved.

I told yesterday night, to Jay that I would test all 4 methods and the
stupid method I was thinking of the first time that night when I saw Jon''s
code. Herfried said from that, that it would become slow with a string from
10Mb. So I told Herfried that I would make the test program if he would type
in a real mixed string for me. But till now he did not send that. (Or maybe
he has again problems with the newsgroup server)

To Jay B I told also that I would try to test extra the difference between
the Microsoft.visual basic function Instr and the system function indexof.

The methods I tested were:
- a do until method with index of (Jay B)
- a do method with Instr (Jon)
- the same I changed something to indexof (Jon)
Those works all with strings
The others only with characters as a search item
- a stupid method that only needs 2 lines code what became in my thoughts
yesterday night
- a indexof with a char (Jay B)
- a for each with a char (Jay B)
I made a test program that I send with this message beneath.
Because all is dependable on the computer you use, I don''t give absolute
figures if you wish you can try it yourself. On my computer it is impossible
to see with any method a difference from more than 1/1000 of a second with a
string shorter than 5000 characters.
With more than that amount of characters that the stupid method I thought of
yesterday becomes visible slower.

When it are real long strings, than with a charsearch was in my test the
fastest method the "do for loop" with "indexof" and second was the for "each
char" both from Jay B.

But for me the most surprising was that the Microsoft.visualbasic function
with "Instr" from Jon was almost 2 times faster with a 3 character string
than the net.system method "indexoff".

I do the test program beneath; it is made with a windowsform project, and
need 2 textboxes from which textbox1 needs to have multi line true, a
button1 and a large label1.

Texbox1 is for the text to make a string with (automaticly made till
Herfried send his in).
Textbox2 the length of the text string to make (Yes you understand it
till....)

I hope this gives some idea''s (too about some people who said the
microsoft.visualbasic functions are slow and outdated, This you can of
course not test with C#.)
Cor
\\\
Private Sub Button1_Click(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text = "" Then
Me.label1.Text = "Enter strings in uper textbox"
Exit Sub
End If
If Not IsNumeric(Me.TextBox2.Text) Then
Me.label1.Text = "Enter value in down textbox"
Exit Sub
End If
TestString.Build(Me.TextBox1.Text.ToString, CInt(Me.TextBox2.Text))
Dim delimiter As String
If TestString.StringToTest.Length > 3 Then
delimiter = TestString.StringToTest.Substring(0, 3)
Else
Exit Sub
End If
Dim i As Integer
Dim labeltext As New System.Text.StringBuilder
Dim count As Integer
Dim testname As String
For i = 1 To 3
Dim StartTick As Integer = Environment.TickCount
Select Case i
Case 1
testname = "Jay B, string "
count = Test1(TestString.StringToTest, delimiter)
Case 2
testname = "Jon, string "
count = Test2(TestString.StringToTest, delimiter)
Case 3
testname = "Jon, but with indexof"
count = Test3(TestString.StringToTest, delimiter)
End Select
Dim Elapsed As Integer = Environment.TickCount - StartTick
labeltext.Append(testname & "count: " & _
count & " Elapsed : " & Elapsed.ToString & vbCrLf)
Next
delimiter = delimiter.Substring(0, 1)
labeltext.Append("characters" & vbCrLf)
For i = 1 To 6
Dim StartTick As Integer = Environment.TickCount
Select Case i
Case 1
testname = "Jay B, string "
count = Test1(TestString.StringToTest, delimiter)
Case 2
testname = "Jon, string "
count = Test2(TestString.StringToTest, delimiter)
Case 3
testname = "Jon, but with indexof "
count = Test3(TestString.StringToTest, delimiter)
Case 4
If TestString.StringToTest.Length < 599999 Then
testname = "Cor stupid "
count = Test4(TestString.StringToTest, delimiter)
Else
testname = "Skipped test"
End If
Case 5
testname = "Jay B char do until "
count = test5(TestString.StringToTest, delimiter)
Case 6
testname = "Jay B char for each "
count = test6(TestString.StringToTest, delimiter)
End Select
Dim Elapsed As Integer = Environment.TickCount - StartTick
labeltext.Append(testname & "count: " & _
count & " Elapsed : " & Elapsed.ToString & vbCrLf)
Next
Me.label1.Text = labeltext.ToString

End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Me.Button1.Text = "start test"
End Sub
Public Function Test1(ByVal input As String, ByVal delimiter _
As String) As Integer ''Jay B 1(string)
Dim count, index As Integer
index = input.IndexOf(delimiter)
Do Until index < 0
count += 1
index = input.IndexOf(delimiter, index + 1)
Loop
Return count
End Function
Public Function Test2(ByVal strInput As String, ByVal strDelimiter _
As String) As Int32 ''Jon (string)
Dim iStart As Int32, iCount As Int32, iResult As Int32
iStart = 1
iCount = 0
Do
iResult = InStr(iStart, strInput, strDelimiter)
If iResult = 0 Then Exit Do
iCount += 1
iStart = iResult + 1
Loop
Return iCount
End Function
Public Function Test3(ByVal input As String, ByVal delimiter _
As String) As Integer ''Jon with indexof(x,x,x)
Dim iStart As Int32, iCount As Int32, iResult As Int32
iStart = 0
iCount = 0
Do
iResult = input.IndexOf(delimiter, iStart)
If iResult = -1 Then Exit Do
iCount += 1
iStart = iResult + 1
Loop
Return iCount
End Function
Public Function Test4(ByVal input As String, ByVal delimiter _
As String) As Integer ''Cor stupid
Dim teststring As String() = Split(input, delimiter)
Return teststring.Length - 1
End Function
Public Function test5(ByVal input As String, ByVal _
delimiter As Char) As Integer ''Jay 1(char)
Dim count, index As Integer
index = input.IndexOf(delimiter)
Do Until index < 0
count += 1
index = input.IndexOf(delimiter, index + 1)
Loop
Return count
End Function
Public Shared Function test6(ByVal input As String, _
ByVal delimiter As Char) As Integer ''JayB 2(char)
Dim count As Integer
For Each ch As Char In input
If ch = delimiter Then
count += 1
End If
Next ch
Return count
End Function
End Class
Public Class TestString
Private Shared mStringTest As String
Public Shared ReadOnly Property StringToTest() As String
Get
Return mStringTest
End Get
End Property
Public Shared Sub Build(ByVal strToTest As String, ByVal x As Integer)
Dim strTest As New System.Text.StringBuilder
Dim strTextbox As String() = Split(strToTest, vbCrLf)
Do While strTest.ToString.Length < x
Dim i As Integer
For i = 0 To strTextbox.Length - 1
Dim y As Integer
For y = 0 To i
If strTest.ToString.Length < x / 2 Then
strTest.Append(strTest.ToString & strTextbox(i))
Else
strTest.Append(strTest.ToString.Substring(0, x / 2) _
& strTextbox(i))
End If

Next
Next
Loop
mStringTest = strTest.ToString.Substring(0, x)
End Sub
End Class
///

解决方案

Hi Cor,

|| Herfried said from that, that it would become slow
|| with a string from 10Mb. So I told Herfried that I
|| would make the test program if he would type in a
|| real mixed string for me. But till now he did not send
|| that. (Or maybe he has again problems with the
|| newsgroup server)

I''ve just been speaking to Herfried at the Hospital - it''s not looking
good. He got as far as character 432764 before the pain was too much to bear.
The doctors have diagnosed the most severe case of RSI that they have seen in
years. Not surprising when Herfried was typing as fast as he couldto get you
the file in time. Unfortunately amputation may be the most reasonable outcome.
:-((

Regards,
Fergus


"Fergus Cooney" <fi******@tesco.net> scripsit:

Herfried said from that, that it would become slow
with a string from 10Mb. So I told Herfried that I


I told that it will consume a lot of memory, but I never told that the
performance will be bad.
I''ve just been speaking to Herfried at the Hospital
- it''s not looking good. He got as far as character
432764 before the pain was too much to bear. The doctors
have diagnosed the most severe case of RSI that
What''s RSI?
they have seen in years. Not surprising when Herfried was
typing as fast as he couldto get you the file in time.
Unfortunately amputation may be the most reasonable outcome.
:-((



:-(

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>


Hi Herfried,

Repetitive Strain Injury - what you get from typing too much for too long.
How''s the wrist now - do the doctors still think the hand will have to come
off? ;-)

Regards,
Fergus


这篇关于关于在字符串中搜索的测试我向Jay B承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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