Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.scripting.vbscript > #11144
| From | "Mayayana" <mayayana@invalid.nospam> |
|---|---|
| Newsgroups | microsoft.public.scripting.vbscript |
| Subject | Re: VbScript and .NET objects |
| Date | 2015-08-31 09:50 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ms1lq7$1v3$1@dont-email.me> (permalink) |
| References | (3 earlier) <mrvamc$6es$1@dont-email.me> <mrvc7v$d91$1@dont-email.me> <ms0bfn$l4$1@dont-email.me> <ms0g7v$7pk$1@dont-email.me> <ms1ebk$3n3$1@dont-email.me> |
| I don't understand how you turn the initial string of x characters into
| an array of x elements.
It depends on what you're doing. If you look at the
JS De-ob coloring routine I linked you can see that
it's building a new string, avoiding concatenation,
which would be unworkable on such a large scale.
I need to rebuild the string almost character by
character, and it needs to work within a reasonable
amount of time on, say, 100 KB of script.
If you want to parse a string and
add lots of substrings then the fastest method is
to parse the string non-case-sensitive and then build
the new one in an array. You can't use an array for
everything, but you can use it for many things where
one might have used the Mid statement.
For a single replacement it doesn't really matter,
but anyplace where you're doing multiple string
allocations, time can get wasted on a very large
scale.
Replace is surprisingly inefficient on large strings,
for the same reasons, so I try to use Replace only
on small strings and use array string-builders for
the big strings.
I originally got this from VB. Matthew Curland, one
of the original VB developers. He explained in his book
that Join walks the array, measuring everything, and
then only needs to allocate one big string.
In the samples below, I take a string full of "a"
and replace 6 characters at a time with "sample",
using Mid, Left/Right, or an array. The array just
assigns "sample" to each array index and then calls
Join. It's not really a real-world test, but it
demonstrates the point. My results in seconds:
string length:
100,000 300,000 1,000,000
Mid .89 51.2
LR .843 50.51 718.812
Array .015 .046 .18
While L/R was fairly quick with a string
100,000 characters long, as you can see,
it gets crazy inefficient as it gets longer.
Almost 12 minutes for a string 1,000,000
characters long! The big drain is when it
needs to allocate big strings in every iteration.
I changed the test to 300,000 from 1,000,000
after the LR test, so I wouldn't be here all morning!
That's why I have no results for a test of Mid on
a string 1,000,000 characters long.
But with the array, the length of the string
hardly matters because there is only one
large string allocation. Here's the code:
Dim s2, T1, T2
T1 = Timer
'TestMid 2
'TestLR 2
TestA1 2
T2 = Timer
MsgBox Len(s2) & vbCrLf & CStr(T2 - T1)
MsgBox s2
Sub TestMid(TestVersion)
Dim s1, i1, i2
If TestVersion = 1 Then
i2 = 100000
Else
i2 = 300000
End If
s1 = "sample"
s2 = String(i2, "a")
i1 = 10
Do While i1 < (i2 - 10)
s2 = mid(s2, 1, i1) & s1 & mid(s2, i1 + 7)
i1 = i1 + 6
Loop
End Sub
Sub TestA1(TestVersion)
Dim A1(), s1, i1, i2
If TestVersion = 1 Then
i2 = 100000
Else
i2 = 300000
End If
s1 = "sample"
ReDim A1(i2 \ 6)
For i1 = 0 to UBound(A1)
A1(i1) = s1
Next
s2 = Join(A1, "")
End Sub
Sub TestLR(TestVersion)
Dim s1, i1, i2
If TestVersion = 1 Then
i2 = 100000
Else
i2 = 300000
End If
s1 = "sample"
s2 = String(i2, "a")
i1 = 10
Do While i1 < (i2 - 10)
s2 = Left(s2, i1) & s1 & Right(s2, Len(s2) - (i1 + 6))
i1 = i1 + 6
Loop
End Sub
Back to microsoft.public.scripting.vbscript | Previous | Next — Previous in thread | Next in thread | Find similar
VbScript and .NET objects noone@no.void (Reventlov) - 2015-08-29 12:40 +0000
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2015-08-29 10:39 -0400
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2015-08-29 10:55 -0400
Re: VbScript and .NET objects GS <gs@v.invalid> - 2015-08-30 12:25 -0400
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2015-08-30 12:55 -0400
Re: VbScript and .NET objects GS <gs@v.invalid> - 2015-08-30 13:02 -0400
Re: VbScript and .NET objects GS <gs@v.invalid> - 2015-08-30 13:10 -0400
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2015-08-30 13:42 -0400
Re: VbScript and .NET objects GS <gs@v.invalid> - 2015-08-30 14:04 -0400
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2015-08-30 17:05 -0400
Re: VbScript and .NET objects GS <gs@v.invalid> - 2015-08-30 17:14 -0400
Re: VbScript and .NET objects "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2015-08-30 21:45 -0400
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2015-08-30 23:09 -0400
Re: VbScript and .NET objects "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2015-08-31 07:40 -0400
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2015-08-31 09:50 -0400
Re: VbScript and .NET objects johnbeschler@gmail.com - 2017-03-15 10:24 -0700
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2017-03-15 14:40 -0400
Re: VbScript and .NET objects "Mayayana" <mayayana@invalid.nospam> - 2017-03-15 21:38 -0400
csiph-web