Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11130

Re: VbScript and .NET objects

From "Mayayana" <mayayana@invalid.nospam>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: VbScript and .NET objects
Date 2015-08-29 10:39 -0400
Organization A noiseless patient Spider
Message-ID <mrsftt$lp0$1@dont-email.me> (permalink)
References <55e1a84f.4061562@nntp.aioe.org>

Show all headers | View raw


  It's never seemed to me that .Net is worth the
trouble. First, it's only useful for private code. There's
no guarantee that people with XP will have .Net
installed.

  Second, I just don't see what's so great. VBS has
Dictionaries. We have arrays. The only thing I really
miss is the mid *statement*, which VB has, allowing
editing of strings without new allocations. But the
Mid statement is essentially the same as building
strings from arrays, which can be done in VBS.
Comparing .Net StringWriter or StringBuilder to
concatenation is a bit like comparing a mediocre
rake to raking your yard with a fork. You need to
compare it fairly, to the best rake you currently have.

 It's *extremely* slow to do:

For i = 1 to 100000
  s = s & "newstring"
Next

  The reason for that is because each iteration requires
allocation of a new string, and the size of that keeps
growing. By the end each iteration is allocating almost
1 MB (or 2 MB for unicode).

  But look at the following tests. Here are my results,
testing StringWriter, StringBuilder and simple VBS array
Join:

Concatenating string of instances
of the word "sample":

Time in seconds for given number of iterations:

                100,000       1,000,000

Stringwriter:   1.25            9.89
StringBuilder:  1.0468        10.6406
VBS array:      0.109375     0.5625

  The results vary slightly with each run, but those
numbers are typical on my machine.
  It's clear from those numbers that a VBS array
far faster. And since the same relative speed holds
up for 100,000 or 1,000,000 iterations, it's clear
that instantiating and releasing the objects is not
a factor in the time required. (However, marshaling
probably is a factor. WScript needs to call into a
separate process for each iteration. As with using
any COM object, that's very inefficient.)
Here's the code, if you want to test it:

Dim s2, T1, T2

T1 = Timer
'TestSW  2
'TestA 2
TestSB 2
T2 = Timer

MsgBox Len(s2) & vbCrLf & CStr(T2 - T1)

Sub TestSW(TestVersion)
   Dim SW, s1, i1, i2
    Set SW = CreateObject("System.IO.StringWriter")
  If TestVersion = 1 Then
    i2 = 100000
  Else
    i2 = 1000000
  End If
s1 = "sample"
 For i1 = 1 to i2
    SW.write_12 s1
 Next

  s2 = SW.GetStringBuilder().ToString()
  Set SW = Nothing
End Sub

Sub TestA(TestVersion)
   Dim A1(), s1, i1, i2

  If TestVersion = 1 Then
    i2 = 100000
  Else
    i2 = 1000000
  End If
  s1 = "sample"
  ReDim A1(i2)
 For i1 = 0 to i2
    A1(i1) = s1
 Next
   s2 = Join(A1, "")
End Sub

Sub TestSB(TestVersion)
  Dim SB, s1, i2, i1
  s1 = "sample"
  Set SB = CreateObject("System.Text.StringBuilder")
  If TestVersion = 1 Then
    i2 = 100000
  Else
    i2 = 1000000
  End If

For i1 = 1 to i2
  SB.Append_3 s1
Next

 s2 = SB.ToString

  Set SB = Nothing
End Sub





Back to microsoft.public.scripting.vbscript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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