|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
vb.net, so slow !!!???I have read a few articles regarding the slow speed of vb.net application, did a little experiment myself. It's a simple multiple loop here are the code in vb.net and vb6 vb.net: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim A0 As Short Dim A1 As Short Dim A2 As Short Dim A3 As Short Dim A4 As Short Dim A5 As Short Dim Count As Integer = 0 For A0 = 1 To 45 For A1 = A0 + 1 To 46 For A2 = A1 + 1 To 47 For A3 = A2 + 1 To 48 For A4 = A3 + 1 To 49 For A5 = A4 + 1 To 50 Count += 1 Label1.Text = Count Label1.Refresh() Next Next Next Next Next Next Label1.Text = Count Label1.Refresh() End Sub vb6: Private Sub Command1_Click() Dim count As Long Dim A0 As Integer Dim A1 As Integer Dim A2 As Integer Dim A3 As Integer Dim A4 As Integer Dim A5 As Integer count = 0 For A0 = 1 To 45 For A1 = A0 + 1 To 46 For A2 = A1 + 1 To 47 For A3 = A2 + 1 To 48 For A4 = A3 + 1 To 49 For A5 = A4 + 1 To 50 count = count + 1 Label1.Caption = count Label1.Refresh Next Next Next Next Next Next Label1.Caption = count Label1.Refresh End Sub The results are shocking. It only took about 3 minutes for vb6 application to finish the loop. For vb.net, didn't even finish the loop in 15 minutes, I lost patience, close the program anyway. Don't know how long it would actually take. I'm just a beginner on VB, couldn't figure out why. Can anybody explain to me, thank u. ZW,
Why are you running in VB6 in its internal (int) format and are converting everytime that internal Integer format in VBNet to short. (You should in top of your program set Option Strict ON if you do this kind of tests, than you see it direct). Try it again and set than the following changes in your code. > vb.net: All shorts has to be Integer> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Dim A0 As Short > Dim A1 As Short Label1.Text = Count.ToString> Dim A2 As Short > Dim A3 As Short > Dim A4 As Short > Dim A5 As Short > Dim Count As Integer = 0 > For A0 = 1 To 45 > For A1 = A0 + 1 To 46 > For A2 = A1 + 1 To 47 > For A3 = A2 + 1 To 48 > For A4 = A3 + 1 To 49 > For A5 = A4 + 1 To 50 > Count += 1 > Label1.Text = Count > Label1.Refresh() I am currious for your result then> Next > Next > Next > Next > Next > Next > Label1.Text = Count.ToString > Label1.Refresh() > End Sub Cor zw2***@gmail.com wrote:
Show quoteHide quote > Hi, While, as Cor pointed out, you have type conversion issues in your code> I have read a few articles regarding the slow speed of vb.net > application, did a little experiment myself. It's a simple multiple > loop here are the code in vb.net and vb6 > vb.net: > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Dim A0 As Short > Dim A1 As Short > Dim A2 As Short > Dim A3 As Short > Dim A4 As Short > Dim A5 As Short > Dim Count As Integer = 0 > For A0 = 1 To 45 > For A1 = A0 + 1 To 46 > For A2 = A1 + 1 To 47 > For A3 = A2 + 1 To 48 > For A4 = A3 + 1 To 49 > For A5 = A4 + 1 To 50 > Count += 1 > Label1.Text = Count > Label1.Refresh() > Next > Next > Next > Next > Next > Next > Label1.Text = Count > Label1.Refresh() > End Sub > vb6: > Private Sub Command1_Click() > Dim count As Long > Dim A0 As Integer > Dim A1 As Integer > Dim A2 As Integer > Dim A3 As Integer > Dim A4 As Integer > Dim A5 As Integer > count = 0 > For A0 = 1 To 45 > For A1 = A0 + 1 To 46 > For A2 = A1 + 1 To 47 > For A3 = A2 + 1 To 48 > For A4 = A3 + 1 To 49 > For A5 = A4 + 1 To 50 > count = count + 1 > Label1.Caption = count > Label1.Refresh > Next > Next > Next > Next > Next > Next > Label1.Caption = count > Label1.Refresh > End Sub > > The results are shocking. It only took about 3 minutes for vb6 > application to finish the loop. For vb.net, didn't even finish the loop > in 15 minutes, I lost patience, close the program anyway. Don't know > how long it would actually take. > I'm just a beginner on VB, couldn't figure out why. Can anybody explain > to me, thank u. that will definately cause some performance loss - the main problem is the UI update. If you take out the lable update in the loop, the loop will complete almost immediately. It's a fact, that VB.NET is slower when it comes to UI operations. If you needed this is in production code, I would be inclined to not update ever iteration of the loop. -- Tom Shelton [MVP] <zw2***@gmail.com> schrieb:
Show quoteHide quote > vb.net: First, I suggest to replace 'As Short' with 'As Integer' in the VB.NET > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Dim A0 As Short > Dim A1 As Short > Dim A2 As Short > Dim A3 As Short > Dim A4 As Short > Dim A5 As Short > Dim Count As Integer = 0 > For A0 = 1 To 45 > For A1 = A0 + 1 To 46 > For A2 = A1 + 1 To 47 > For A3 = A2 + 1 To 48 > For A4 = A3 + 1 To 49 > For A5 = A4 + 1 To 50 > Count += 1 > Label1.Text = Count > Label1.Refresh() > Next > Next > Next > Next > Next > Next > Label1.Text = Count > Label1.Refresh() > End Sub > vb6: > Private Sub Command1_Click() > Dim count As Long > Dim A0 As Integer > Dim A1 As Integer > Dim A2 As Integer > Dim A3 As Integer > Dim A4 As Integer > Dim A5 As Integer > count = 0 > For A0 = 1 To 45 > For A1 = A0 + 1 To 46 > For A2 = A1 + 1 To 47 > For A3 = A2 + 1 To 48 > For A4 = A3 + 1 To 49 > For A5 = A4 + 1 To 50 > count = count + 1 > Label1.Caption = count > Label1.Refresh > Next > Next > Next > Next > Next > Next > Label1.Caption = count > Label1.Refresh > End Sub > > The results are shocking. It only took about 3 minutes for vb6 > application to finish the loop. For vb.net, didn't even finish the loop > in 15 minutes, I lost patience, close the program anyway. Don't know > how long it would actually take. version. In addition note that the JIT compiler will have to create a native code version of the method prior to executing it the first time, which will take some microseconds too. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> zw2000,
Congratulations! you have successfully demonstrated that marshaling from managed code (.NET) to unmanaged code takes time. As Tom pointed out, all your time is spent in the UI update: | Label1.Text = Count Removing those two statements from the middle of your loop causes the loop | Label1.Refresh() to finish "in a matter of seconds". Because updating the UI takes time in both VB6 & more so in .NET I normally try to be a little more friendly when updating the UI, such as relying on the windows Paint event, or only updating status's every n iterations... Remember that a number of framework controls, such as Label are based on Win32 controls. When you set properties (.Text) or call methods (.Refresh) the CLR needs to marshal the data from the .NET managed world to the Win32 unmanaged world. Changing the variables from Short to Integer has a slight impact but its barely perceivable here. I would recommend using Integer here more because Short is not offering any real benefit here. Not because there is a fraction of a millisecond speed improvement... Besides the CLR actually uses Int32 for the calculation any way then VB converts them back to Int16 to store the value... I would consider using Short (Int16) more where size was a consideration, such as interop code, I really need to limit the range of the values, or I was storing a large number of them such as an array... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net <zw2***@gmail.com> wrote in message news:1146540817.117105.13310@v46g2000cwv.googlegroups.com... | Hi, | I have read a few articles regarding the slow speed of vb.net | application, did a little experiment myself. It's a simple multiple | loop here are the code in vb.net and vb6 | vb.net: | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As | System.EventArgs) Handles Button1.Click | Dim A0 As Short | Dim A1 As Short | Dim A2 As Short | Dim A3 As Short | Dim A4 As Short | Dim A5 As Short | Dim Count As Integer = 0 | For A0 = 1 To 45 | For A1 = A0 + 1 To 46 | For A2 = A1 + 1 To 47 | For A3 = A2 + 1 To 48 | For A4 = A3 + 1 To 49 | For A5 = A4 + 1 To 50 | Count += 1 | Label1.Text = Count | Label1.Refresh() | Next | Next | Next | Next | Next | Next | Label1.Text = Count | Label1.Refresh() | End Sub | vb6: | Private Sub Command1_Click() | Dim count As Long | Dim A0 As Integer | Dim A1 As Integer | Dim A2 As Integer | Dim A3 As Integer | Dim A4 As Integer | Dim A5 As Integer | count = 0 | For A0 = 1 To 45 | For A1 = A0 + 1 To 46 | For A2 = A1 + 1 To 47 | For A3 = A2 + 1 To 48 | For A4 = A3 + 1 To 49 | For A5 = A4 + 1 To 50 | count = count + 1 | Label1.Caption = count | Label1.Refresh | Next | Next | Next | Next | Next | Next | Label1.Caption = count | Label1.Refresh | End Sub | | The results are shocking. It only took about 3 minutes for vb6 | application to finish the loop. For vb.net, didn't even finish the loop | in 15 minutes, I lost patience, close the program anyway. Don't know | how long it would actually take. | I'm just a beginner on VB, couldn't figure out why. Can anybody explain | to me, thank u. | thanks all for the reply, I change the codes as all of you said, now
both almost finish instantly. I learn something new everyday. zw2***@gmail.com wrote:
> thanks all for the reply, I change the codes as all of you said, now Have they really addressed your question? I mean, I'm left with one:> both almost finish instantly. I learn something new everyday. Why is VB6 a lot faster then VB.net using the same code? zw2000, have you run another test after the suggested modifications to your benchmark code? I'm curious as to which VB will outperform the other. See Tom's reply : this is the UI update that is the main culprit (likely
because of interop), the simple solution he mentioned is to avoid updating too much frequently the UI). -- Show quoteHide quotePatrice <alc***@gmail.com> a écrit dans le message de news: 1146582033.465653.204***@e56g2000cwe.googlegroups.com... > > zw2***@gmail.com wrote: >> thanks all for the reply, I change the codes as all of you said, now >> both almost finish instantly. I learn something new everyday. > > > Have they really addressed your question? I mean, I'm left with one: > Why is VB6 a lot faster then VB.net using the same code? > > zw2000, have you run another test after the suggested modifications to > your benchmark code? I'm curious as to which VB will outperform the > other. > Alcurb,
> This is told in this thread by Tom and by Jay. One of those things is by > zw2000, have you run another test after the suggested modifications to > your benchmark code? I'm curious as to which VB will outperform the > other. refreshing the contents of controls with the goal to do it in nanoseconds. As you probably know is that not readable for humans, therefore culprit to take attention to that or better taking a lot of performance time trying doing that (painting is the most important performance eater). Cor | Have they really addressed your question? I mean, I'm left with one: VB6 runs as native code, there is no marshalling happening.| Why is VB6 a lot faster then VB.net using the same code? As I stated earlier VB.NET runs as managed code, it needs to marshal arguments from the managed code to the unmanaged code. By "marshalling" code I mean the CLR (the runtime) looks at the managed (.NET) stack frame, copies & converts arguments to the Win32 stack frame, then calls the Win32 version of the function. When the Win32 version is done, the CLR then copies & converts any return values back to the managed stack frame (from the Win32 stack frame)... zw2000 was making 2 calls per iteration that would require marshaling in their sample. There are a plethora of articles on the subject of Marshalling. This may be a good start: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/highperfmanagedapps.asp At the very least it describes a tool that may help identify bottle necks in your managed code. Although the "COM Interop and Platform Invoke" section provides some good quick info on Interop & Marshalling... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net <alc***@gmail.com> wrote in message news:1146582033.465653.204220@e56g2000cwe.googlegroups.com... | | zw2***@gmail.com wrote: | > thanks all for the reply, I change the codes as all of you said, now | > both almost finish instantly. I learn something new everyday. | | | Have they really addressed your question? I mean, I'm left with one: | Why is VB6 a lot faster then VB.net using the same code? | | zw2000, have you run another test after the suggested modifications to | your benchmark code? I'm curious as to which VB will outperform the | other. | "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> schrieb: I think this is only partly true. While VB6 supports Unicode strings, it >| Have they really addressed your question? I mean, I'm left with one: > | Why is VB6 a lot faster then VB.net using the same code? > VB6 runs as native code, there is no marshalling happening. uses the ANSI versions of the API functions and thus marshalling from UTF-16 to the system's ANSI codepage must be performed. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried,
Yes for String versions of API's on platforms that are Ansi only (Win95) that's probably true. Although I'm not sure if on "NT" platforms VB6 is calling the Ansi version of the API directly or calling the respective Unicode or Ansi version based on the OS its on. As it would be horrible inefficient to convert the string to Ansi call the Ansi version, then have the Ansi version convert it back to call the Unicode version on NT/XP/Windows Server platforms where the OS is running Unicode natively... My understanding is that VB6 has the equivalent of: http://www.microsoft.com/downloads/details.aspx?FamilyID=73BA7BD7-ED06-4F0D-80A4-2A7EEAEE17E2&displaylang=en That is it runs Unicode & effectively calls the Unicode API on "NT" platforms, on Windows 95, 98, & ME it effectively calls a helper function that then converts the strings to call the ANSI API. -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:ufFg7fpbGHA.4672@TK2MSFTNGP04.phx.gbl... | "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> schrieb: | >| Have they really addressed your question? I mean, I'm left with one: | > | Why is VB6 a lot faster then VB.net using the same code? | > VB6 runs as native code, there is no marshalling happening. | | I think this is only partly true. While VB6 supports Unicode strings, it | uses the ANSI versions of the API functions and thus marshalling from UTF-16 | to the system's ANSI codepage must be performed. | | -- | M S Herfried K. Wagner | M V P <URL:http://dotnet.mvps.org/> | V B <URL:http://classicvb.org/petition/> |
How about: How do I attach a file to an email w/MailTo: ?
Access rights for a web application to read a text file on a different server Collections strong reference between objects in different assemblies Converting VB Script Code to VB.NET 2005 SelectionChangeCommitted event TCP send & Recieve How to display Printer Settings Dialogue? Creating Worksheets from Existing Excel Instances in VB.NET? Appending two data tables |
|||||||||||||||||||||||