VB6 Speed vs VB.Net Speed 
Author Message
 VB6 Speed vs VB.Net Speed

I have a very small block of code I wrote in vb6, it's a tide
calculation which I took from Dave Flaters xtide program and put into
vb. I re-wrote the calculation for vb.net and it takes on average 1.5
times as long to run. There is not much to it. Can anyone help on this.
Here is the vb6 code, with a few extra calculations in it(and it still
runs 1.5 times as fast) and then the vb.net code. In both versions I
grab  variables from a database and put them into arrays and them run
calculations on them. Even the area before these blocks runs faster in
vb6 although the difference is not as great. I have a 1.2 athlon with a
gig of ram if that matters. The formatting of longer lines is off in the
message.

--------VB6-----------------
For dt = 1 To 1440
     a = 0
     rs.MoveFirst
     Datum = rs("Datum")
     For a = 0 To rs.RecordCount - 1
         tide = tide + work(a) * _
         cos_degrees(cst_speeds(a) * ((T - epoch) - 18000) + _
         (cst_epochs(a) - loc_epoch(a)))
         tide = FormatNumber(tide, 15)
      Next
      tide = (tide * amplitude) + Datum
      newdate = FormatDateTime(DateAdd("s", ((T - 18000) + 3600),
txtStartDate), vbGeneralDate)
        txtString = txtString  & newdate & " : " & FormatNumber(tide, 6)
& vbCrLf  
     T = T + 60
     tide = 0
Next
txtTides.Text = txtString

Private Function cos_degrees(ByVal x As Double)
  cos_degrees = FormatNumber(Cos((x * 3.141592654) / 180), 15)
End Function
----------vb.net version---------------------------------
For dt = 1 To 1440
   For a = 0 To num_const
       tide = tide + Work(a) * _
       cos_degrees(cst_speeds(a) * ((t - tepoch) - 18000) + _
       (cst_epochs(a) - loc_epoch(a)))
       tide = FormatNumber(tide, 15)
   Next
   tide = (tide * Amplitude) + DATUM
   newdate = FormatDateTime(DateAdd("s", ((t - 18000) + 3600),
txtStartDate.Text), vbGeneralDate)
   ttide = ttide & newdate & " : " & FormatNumber(tide, 6) & vbCrLf
   t = t + 60
   tide = 0
Next
txtTides.Text = ttide

Private Function cos_degrees(ByVal x As Double)
cos_degrees = FormatNumber(System.Math.Cos((x * 3.141592654) / 180), 15)
End Function



Mon, 27 Dec 2004 19:22:29 GMT  
 VB6 Speed vs VB.Net Speed
Michael,

- Turn on Option Strict and fix your code to work with that.

- Get rid if the FormatNumber calls in the calculations, I don't know
why you have them there in the first place. It just causes unneccesary
Double->String->Double conversions.

Mattias

===
Mattias Sj?gren (VB MVP)

http://www.msjogren.net/dotnet/



Mon, 27 Dec 2004 20:14:57 GMT  
 VB6 Speed vs VB.Net Speed
arrays are quite slow on .NET, but they get faster with synch, whats the
better way of doing this?
datarows, are like arrays aswell, arent they? whats the fastest way to deal
with them?

at the moment I am doing stuff like:


Quote:
> Michael,

> - Turn on Option Strict and fix your code to work with that.

> - Get rid if the FormatNumber calls in the calculations, I don't know
> why you have them there in the first place. It just causes unneccesary
> Double->String->Double conversions.

> Mattias

> ===
> Mattias Sj?gren (VB MVP)

> http://www.msjogren.net/dotnet/



Mon, 27 Dec 2004 20:39:06 GMT  
 VB6 Speed vs VB.Net Speed

Total_Array = Total_Array.Synchronized(Total_Array)

don't know what this means, but it makes my app faster :)


Quote:
> I have a very small block of code I wrote in vb6, it's a tide
> calculation which I took from Dave Flaters xtide program and put into
> vb. I re-wrote the calculation for vb.net and it takes on average 1.5
> times as long to run. There is not much to it. Can anyone help on this.
> Here is the vb6 code, with a few extra calculations in it(and it still
> runs 1.5 times as fast) and then the vb.net code. In both versions I
> grab  variables from a database and put them into arrays and them run
> calculations on them. Even the area before these blocks runs faster in
> vb6 although the difference is not as great. I have a 1.2 athlon with a
> gig of ram if that matters. The formatting of longer lines is off in the
> message.

> --------VB6-----------------
> For dt = 1 To 1440
>      a = 0
>      rs.MoveFirst
>      Datum = rs("Datum")
>      For a = 0 To rs.RecordCount - 1
>          tide = tide + work(a) * _
>          cos_degrees(cst_speeds(a) * ((T - epoch) - 18000) + _
>          (cst_epochs(a) - loc_epoch(a)))
>          tide = FormatNumber(tide, 15)
>       Next
>       tide = (tide * amplitude) + Datum
>       newdate = FormatDateTime(DateAdd("s", ((T - 18000) + 3600),
> txtStartDate), vbGeneralDate)
>         txtString = txtString  & newdate & " : " & FormatNumber(tide, 6)
> & vbCrLf
>      T = T + 60
>      tide = 0
> Next
> txtTides.Text = txtString

> Private Function cos_degrees(ByVal x As Double)
>   cos_degrees = FormatNumber(Cos((x * 3.141592654) / 180), 15)
> End Function
> ----------vb.net version---------------------------------
> For dt = 1 To 1440
>    For a = 0 To num_const
>        tide = tide + Work(a) * _
>        cos_degrees(cst_speeds(a) * ((t - tepoch) - 18000) + _
>        (cst_epochs(a) - loc_epoch(a)))
>        tide = FormatNumber(tide, 15)
>    Next
>    tide = (tide * Amplitude) + DATUM
>    newdate = FormatDateTime(DateAdd("s", ((t - 18000) + 3600),
> txtStartDate.Text), vbGeneralDate)
>    ttide = ttide & newdate & " : " & FormatNumber(tide, 6) & vbCrLf
>    t = t + 60
>    tide = 0
> Next
> txtTides.Text = ttide

> Private Function cos_degrees(ByVal x As Double)
> cos_degrees = FormatNumber(System.Math.Cos((x * 3.141592654) / 180), 15)
> End Function



Mon, 27 Dec 2004 20:40:41 GMT  
 VB6 Speed vs VB.Net Speed
Micheal,
    Things will speed up if you use 'native' VB.NET methods and use a
StringBuilder instead of just appending strings which is a very expensive
operation in .NET.
Dim sb as new System.Text.StringBuilder()
Dim theDate as System.Date.DateTime
Dim startDate as System.Date.DateTime =
Convert.ToDateTime(txtStartDate.Text)
and in the loop theDate = startDate.AddSeconds((t - 18000) + 3600)
Use sb.AppendFormat("{0} : {1:D,6}{2}", theDate.ToString(), tide,
Environment.NewLine)
to build your string then set txtTides.Text = sb.ToString().
The number format specifier ({1:D,6}) might not be exactly what you want but
it should server as a starting point.
    The StringBuilder may get the biggest performance gain as it removes the
creation of a large number of strings.

Ron Allen

Quote:
> I have a very small block of code I wrote in vb6, it's a tide
> calculation which I took from Dave Flaters xtide program and put into
> vb. I re-wrote the calculation for vb.net and it takes on average 1.5
> times as long to run. There is not much to it. Can anyone help on this.
> Here is the vb6 code, with a few extra calculations in it(and it still
> runs 1.5 times as fast) and then the vb.net code. In both versions I
> grab  variables from a database and put them into arrays and them run
> calculations on them. Even the area before these blocks runs faster in
> vb6 although the difference is not as great. I have a 1.2 athlon with a
> gig of ram if that matters. The formatting of longer lines is off in the
> message.

> --------VB6-----------------
> For dt = 1 To 1440
>      a = 0
>      rs.MoveFirst
>      Datum = rs("Datum")
>      For a = 0 To rs.RecordCount - 1
>          tide = tide + work(a) * _
>          cos_degrees(cst_speeds(a) * ((T - epoch) - 18000) + _
>          (cst_epochs(a) - loc_epoch(a)))
>          tide = FormatNumber(tide, 15)
>       Next
>       tide = (tide * amplitude) + Datum
>       newdate = FormatDateTime(DateAdd("s", ((T - 18000) + 3600),
> txtStartDate), vbGeneralDate)
>         txtString = txtString  & newdate & " : " & FormatNumber(tide, 6)
> & vbCrLf
>      T = T + 60
>      tide = 0
> Next
> txtTides.Text = txtString

> Private Function cos_degrees(ByVal x As Double)
>   cos_degrees = FormatNumber(Cos((x * 3.141592654) / 180), 15)
> End Function
> ----------vb.net version---------------------------------
> For dt = 1 To 1440
>    For a = 0 To num_const
>        tide = tide + Work(a) * _
>        cos_degrees(cst_speeds(a) * ((t - tepoch) - 18000) + _
>        (cst_epochs(a) - loc_epoch(a)))
>        tide = FormatNumber(tide, 15)
>    Next
>    tide = (tide * Amplitude) + DATUM
>    newdate = FormatDateTime(DateAdd("s", ((t - 18000) + 3600),
> txtStartDate.Text), vbGeneralDate)
>    ttide = ttide & newdate & " : " & FormatNumber(tide, 6) & vbCrLf
>    t = t + 60
>    tide = 0
> Next
> txtTides.Text = ttide

> Private Function cos_degrees(ByVal x As Double)
> cos_degrees = FormatNumber(System.Math.Cos((x * 3.141592654) / 180), 15)
> End Function



Mon, 27 Dec 2004 21:49:19 GMT  
 VB6 Speed vs VB.Net Speed
Hi Michael,

Everytime you assign a new value to a string, VB.NET creates a new string
with the new value and the old string is disposed (and send to the garbage
collector).

This is a very slow process.

Use StringBuilder (System.Text.StringBuilder) instead, which is much
quicker....

  Dim sb As New System.Text.StringBuilder
  sb.Append("text1")
  sb.Append("text2")
  ..
  sb.Append("textXXX")
  MsgDlg(sb.ToString)

Hopes this helps.

M O J O


Quote:
> I have a very small block of code I wrote in vb6, it's a tide
> calculation which I took from Dave Flaters xtide program and put into
> vb. I re-wrote the calculation for vb.net and it takes on average 1.5
> times as long to run. There is not much to it. Can anyone help on this.
> Here is the vb6 code, with a few extra calculations in it(and it still
> runs 1.5 times as fast) and then the vb.net code. In both versions I
> grab  variables from a database and put them into arrays and them run
> calculations on them. Even the area before these blocks runs faster in
> vb6 although the difference is not as great. I have a 1.2 athlon with a
> gig of ram if that matters. The formatting of longer lines is off in the
> message.

> --------VB6-----------------
> For dt = 1 To 1440
>      a = 0
>      rs.MoveFirst
>      Datum = rs("Datum")
>      For a = 0 To rs.RecordCount - 1
>          tide = tide + work(a) * _
>          cos_degrees(cst_speeds(a) * ((T - epoch) - 18000) + _
>          (cst_epochs(a) - loc_epoch(a)))
>          tide = FormatNumber(tide, 15)
>       Next
>       tide = (tide * amplitude) + Datum
>       newdate = FormatDateTime(DateAdd("s", ((T - 18000) + 3600),
> txtStartDate), vbGeneralDate)
>         txtString = txtString  & newdate & " : " & FormatNumber(tide, 6)
> & vbCrLf
>      T = T + 60
>      tide = 0
> Next
> txtTides.Text = txtString

> Private Function cos_degrees(ByVal x As Double)
>   cos_degrees = FormatNumber(Cos((x * 3.141592654) / 180), 15)
> End Function
> ----------vb.net version---------------------------------
> For dt = 1 To 1440
>    For a = 0 To num_const
>        tide = tide + Work(a) * _
>        cos_degrees(cst_speeds(a) * ((t - tepoch) - 18000) + _
>        (cst_epochs(a) - loc_epoch(a)))
>        tide = FormatNumber(tide, 15)
>    Next
>    tide = (tide * Amplitude) + DATUM
>    newdate = FormatDateTime(DateAdd("s", ((t - 18000) + 3600),
> txtStartDate.Text), vbGeneralDate)
>    ttide = ttide & newdate & " : " & FormatNumber(tide, 6) & vbCrLf
>    t = t + 60
>    tide = 0
> Next
> txtTides.Text = ttide

> Private Function cos_degrees(ByVal x As Double)
> cos_degrees = FormatNumber(System.Math.Cos((x * 3.141592654) / 180), 15)
> End Function



Mon, 27 Dec 2004 22:00:10 GMT  
 VB6 Speed vs VB.Net Speed

Quote:
> Micheal,
>     Things will speed up if you use 'native' VB.NET methods and use a
> StringBuilder instead of just appending strings which is a very expensive
> operation in .NET.
> Dim sb as new System.Text.StringBuilder()
> Dim theDate as System.Date.DateTime
> Dim startDate as System.Date.DateTime =
> Convert.ToDateTime(txtStartDate.Text)
> and in the loop theDate = startDate.AddSeconds((t - 18000) + 3600)
> Use sb.AppendFormat("{0} : {1:D,6}{2}", theDate.ToString(), tide,
> Environment.NewLine)
> to build your string then set txtTides.Text = sb.ToString().
> The number format specifier ({1:D,6}) might not be exactly what you want but
> it should server as a starting point.
>     The StringBuilder may get the biggest performance gain as it removes the
> creation of a large number of strings.

> Ron Allen


> > I have a very small block of code I wrote in vb6, it's a tide
> > calculation which I took from Dave Flaters xtide program and put into
> > vb. I re-wrote the calculation for vb.net and it takes on average 1.5
> > times as long to run. There is not much to it. Can anyone help on this.
> > Here is the vb6 code, with a few extra calculations in it(and it still
> > runs 1.5 times as fast) and then the vb.net code. In both versions I
> > grab  variables from a database and put them into arrays and them run
> > calculations on them. Even the area before these blocks runs faster in
> > vb6 although the difference is not as great. I have a 1.2 athlon with a
> > gig of ram if that matters. The formatting of longer lines is off in the
> > message.

thanks for the help, a combination items in all replys increased the
time by 3 or 400 % and it now beats the vb6 time by triple.


Tue, 28 Dec 2004 02:25:55 GMT  
 VB6 Speed vs VB.Net Speed


Quote:
> Michael,

> - Turn on Option Strict and fix your code to work with that.

> - Get rid if the FormatNumber calls in the calculations, I don't know
> why you have them there in the first place. It just causes unneccesary
> Double->String->Double conversions.

> Mattias

> ===
> Mattias Sj?gren (VB MVP)

> http://www.msjogren.net/dotnet/

Many thanks , this helped alot


Tue, 28 Dec 2004 02:23:55 GMT  
 VB6 Speed vs VB.Net Speed

Quote:

> Total_Array = Total_Array.Synchronized(Total_Array)

> don't know what this means, but it makes my app faster :)

 Is this in place of re-dimming the array?


Tue, 28 Dec 2004 02:27:20 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. VB 3.0 speed vs. VB 4.0 speed

2. Delphi exe speed vs VB exe speed?

3. Delphi speed vs VB speed?

4. VB.NET Speed vs. C

5. VB.net VS VB3 speed

6. Speed, Speed, and Speed!

7. Speed Speed Speed - Cutting down on wasted cycles

8. VB6 to VB.NET - any speed difference?

9. ASP .Net using VB .Net Speed issue

10. Newbie confused: VB6 vs VB.Net vs VBScript vs VBA

11. Newbie confused: VB6 vs VB.Net vs VBscript vs VBA

12. VB vs C# Application Speed

 

 
Powered by phpBB® Forum Software