|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB6 versus VBNet ChallengeCome on, Michael C. I finished my VB6 "Invert Bitmap Challenge" code hours
ago and I told you that I had done so. What's holding you up? Are you still waiting for VB.Net to load? By the way, I've taken the liberty of starting a new thread for this challenge. The old one was a bit long in the tooth. A bit like VB6, eh, Michael ;-) Still some good life in the old dog yet, though! Mike "Mike Williams" <mi***@whiskyandCoke.com> wrote in message Not sure 'bout you, but the crickets are chirpin' here. No sign of Inverted news:OiCuT3ZMIHA.5160@TK2MSFTNGP05.phx.gbl... > Come on, Michael C. I finished my VB6 "Invert Bitmap Challenge" code hours > ago and I told you that I had done so. What's holding you up? Are you > still waiting for VB.Net to load? Bitmap.Net anywhere in sight... > By the way, I've taken the liberty of starting a new thread for this You bet! <g> There's a ton of great code on PSC... since you guys had a > challenge. The old one was a bit long in the tooth. A bit like VB6, eh, > Michael ;-) Still some good life in the old dog yet, though! > > Mike graphics challenge going, this isn't too far off topic... LaVolpe 32bpp DIB Suite http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=67466&lngWId=1 His "Author Picture" looks very familiar, too <g> .....and, for those that haven't been to PSC before, check these out.... All-Time Hall of Fame http://www.planetsourcecode.com/vb/contest/AllTimeHallOfFame.asp?lngWId=1 -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. In Loving Memory - http://www.vbsight.com/Remembrance.htm "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message I imagine that there will be some inverted bitmaps appearing quite soon. See news:ukqVJejMIHA.2000@TK2MSFTNGP05.phx.gbl... > Not sure 'bout you, but the crickets are chirpin' here. No > sign of Inverted Bitmap.Net anywhere in sight... my post about an hour ago in the "I used to use VB ..." thread. I posted it there because Michael C seems to have ignored my request to take his challenge into a new thread. The gist of my post is that Michael C has refused to take on the task using VB.Net and he wants to do it in C# and I suggested that if he wants to talk about .NET in a VB newsgroup then we have the right to assume that he is talking about VB.Net and that if he wants to talk about how good his beloved C# is in relation to other languages then he really should be posting his stuff on a C or C++ group. Anyway, even though I quite naturally assume that VB6 will not be able to actually beat a lower level language such a C#, I have accepted Michael C's (good surname for him that, innit!) challenge and have asked him to write his stuff in C# and post the result (not the code so that I cannot copy anything) of his speed test and when I see his result I will either publicly give up gracefully (highly unlikely!) or I will attempt to see how close I can get to his result using VB6. Mike Unless you're both testing on identical machines, though, you'll HAVE to post code at some point so that you can each compile it and
compare on your individual machines. (Either that or designate a third party to whom you would send the code privately who would do the comparison.) Rob Show quote "Mike Williams" <mi***@whiskyandCoke.com> wrote in message news:%23KfPcNlMIHA.5160@TK2MSFTNGP05.phx.gbl... > "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message news:ukqVJejMIHA.2000@TK2MSFTNGP05.phx.gbl... > >> Not sure 'bout you, but the crickets are chirpin' here. No >> sign of Inverted Bitmap.Net anywhere in sight... > > I imagine that there will be some inverted bitmaps appearing quite soon. See my post about an hour ago in the "I used to use VB > ..." thread. I posted it there because Michael C seems to have ignored my request to take his challenge into a new thread. The > gist of my post is that Michael C has refused to take on the task using VB.Net and he wants to do it in C# and I suggested that if > he wants to talk about .NET in a VB newsgroup then we have the right to assume that he is talking about VB.Net and that if he > wants to talk about how good his beloved C# is in relation to other languages then he really should be posting his stuff on a C or > C++ group. > > Anyway, even though I quite naturally assume that VB6 will not be able to actually beat a lower level language such a C#, I have > accepted Michael C's (good surname for him that, innit!) challenge and have asked him to write his stuff in C# and post the result > (not the code so that I cannot copy anything) of his speed test and when I see his result I will either publicly give up > gracefully (highly unlikely!) or I will attempt to see how close I can get to his result using VB6. > > Mike > > "Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote in message Yes, I'm sure we will. I certainly intend to post my code as soon as Michael news:%23kY64UlMIHA.4476@TK2MSFTNGP06.phx.gbl... > Unless you're both testing on identical machines, though, you'll > HAVE to post code at some point so that you can each compile > it and compare on your individual machines. C has posted the result of his own speed tests and has confirmed that he has emailed his code to a third party that we can both trust. In fact the sooner he does so, the better. I hope he can post it some time today. I just wanted to make it fair on Michael C so that he could be certain I was not looking at his code and attempting to copy his methods. As soon as he has finished his code and has tested it and has posted the result of his speed test then I will immediately post my own code and my own results. I've actually just put the finishing touches to my own code in the last half hour (although I expect that it will show as being in need of improvement once it has been posted), sticking to his requirement of doing it "manually" (not using any GDI or GDI+ routines that operate on blocks of pixels) and also making sure that my code does not invert any of the padding bytes that will be present on the scanlines of bitmaps which do not otherwise align themselves onto Long boundaries and also making sure that I destroy (or allow VB to destroy) any variables and arrays that I use in the process so that all such variables and arrays are re-created every time the "invert the bitmap" function is called. Oh, yes, and also making sure that it will operate on all sizes of bitmap, not just 1024 x 768 bitmaps. I think that was about it. My VB6 code operates quite quickly (obviously after compiling to a native code exe with all optimizations), although I fully expect it to be beaten by lower level languages such as C#. It is still quite fast though, and it should certainly put down Michael C's suggestion that VB6 would be extremely slow at such things. I am prepared to email it right now to anyone who asks for it and who promises to keep it under wraps until Michael C has posted his own code. Regardless of the outcome, I fully expect Michael C to dig deeply through all emails in the thread and will dig something out that proves I have not strictly followed the rules in some minor respect, and I will be very surprised if he does not do so, unless of course his C# code completely thrashes my VB6 code (rather than merely "beating it" as I expect it will), in which case he will be quite happy ;-) Mike "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message I imagine there will be a lot of good code in that stuff, and it would be news:ukqVJejMIHA.2000@TK2MSFTNGP05.phx.gbl... > There's a ton of great code on PSC... since you guys had > a graphics challenge going, this isn't too far off topic... possible to perform operations such as invert and lots of others on bitmaps using all sorts of GDI and GDI+ routines on the complete bitmap, but of course Michael C's challenge (in which he derides what he seems to perceive as the "slowness" of VB6) is to invert a 24bit bmp on a strictly pixel by pixel basis, which will of course be quite a bit slower whatever language you use. Anyway, I'm up for it if he is ;-) Mike
Show quote
"Mike Williams" <mi***@whiskyandCoke.com> wrote in message If there are GDI and GDI+ routines available, why not use them?news:euHqtQlMIHA.4712@TK2MSFTNGP04.phx.gbl... > "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message > news:ukqVJejMIHA.2000@TK2MSFTNGP05.phx.gbl... > >> There's a ton of great code on PSC... since you guys had >> a graphics challenge going, this isn't too far off topic... > > I imagine there will be a lot of good code in that stuff, and it would be > possible to perform operations such as invert and lots of others on bitmaps > using all sorts of GDI and GDI+ routines on the complete bitmap, but of course > Michael C's challenge (in which he derides what he seems to perceive as the > "slowness" of VB6) is to invert a 24bit bmp on a strictly pixel by pixel > basis, which will of course be quite a bit slower whatever language you use. > Anyway, I'm up for it if he is ;-) > I'm quite puzzled by the purpose of a test to see which language is faster at doing something the slow way. :) On Nov 28, 2:05 am, "Mike Williams" <mi***@whiskyandCoke.com> wrote: Mike...> Come on, Michael C. I finished my VB6 "Invert Bitmap Challenge" code hours > ago and I told you that I had done so. What's holding you up? Are you still > waiting for VB.Net to load? > > By the way, I've taken the liberty of starting a new thread for this > challenge. The old one was a bit long in the tooth. A bit like VB6, eh, > Michael ;-) Still some good life in the old dog yet, though! > > Mike I'm not sure if Michael C will ever respond - but, I would be happy to have a go at a VB.NET version. The problem is I'm not a graphics guy, by any stretch of the imagination, and so I'm not sure what you mean by inverting the bitmap? Do you mean creating a negative image? Do you mean actually fliping the image? And can you give me a quick primer of the basic algorithm? I mean, what do I have to do to each pixel? Sorry, if these are stupid questions, but like I said, I don't do graphics AT ALL. -- Tom Shelton On Nov 29, 12:26 am, Tom Shelton <tom_shel***@comcast.net> wrote:
Show quote > On Nov 28, 2:05 am, "Mike Williams" <mi***@whiskyandCoke.com> wrote: Since no one has responded - here is an app that converts each pixel> > > Come on, Michael C. I finished my VB6 "Invert Bitmap Challenge" code hours > > ago and I told you that I had done so. What's holding you up? Are you still > > waiting for VB.Net to load? > > > By the way, I've taken the liberty of starting a new thread for this > > challenge. The old one was a bit long in the tooth. A bit like VB6, eh, > > Michael ;-) Still some good life in the old dog yet, though! > > > Mike > > Mike... > > I'm not sure if Michael C will ever respond - but, I would be happy to > have a go at a VB.NET version. The problem is I'm not a graphics guy, > by any stretch of the imagination, and so I'm not sure what you mean > by inverting the bitmap? Do you mean creating a negative image? Do > you mean actually fliping the image? And can you give me a quick > primer of the basic algorithm? I mean, what do I have to do to each > pixel? Sorry, if these are stupid questions, but like I said, I don't > do graphics AT ALL. > > -- > Tom Shelton into it's complement: Option Strict On Option Explicit On Imports System Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Imports System.Runtime.InteropServices Imports System.Diagnostics Module Module1 Private Const MAX_VALUE As Byte = 255 Sub Main() Dim bmp As New Bitmap("blizz2001-1024.bmp") Dim sw As New Stopwatch() sw.Start() For i As Integer = 0 To 1000 ComplementImage(bmp) Next i Console.WriteLine(sw.Elapsed()) End Sub Private Sub ComplementImage(ByVal bmp As Bitmap) Dim bmpData As BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat) Dim ptr As IntPtr = bmpData.Scan0 For i As Integer = 0 To bmpData.Height - 1 For j As Integer = 0 To bmpData.Width - 1 Dim component As Byte = Marshal.ReadByte(ptr) Marshal.WriteByte(ptr, MAX_VALUE - component) ptr = New IntPtr(ptr.ToInt32() + 3) Next ptr = New IntPtr(ptr.ToInt32() + (bmpData.Stride - bmpData.Width * 3)) Next bmp.UnlockBits(bmpData) End Sub End Module I would give a timing - but it is meaningless two compare except on the same machine. And this probably isn't even doing the right thing :) Anyway, there you have it. -- Tom Shelton "Tom Shelton" <tom_shel***@comcast.net> wrote in message Well I've taken it to mean flipping each bit in each data byte in the image, news:e4a21924-00ea-4e34-83d4-4e252edc6594@e6g2000prf.googlegroups.com... > Mike... > I'm not sure if Michael C will ever respond - but, I would be > happy to have a go at a VB.NET version. The problem is > I'm not a graphics guy, by any stretch of the imagination, and > so I'm not sure what you mean by inverting the bitmap? so that for example any bytes with &HFFFFFFFF (white) become &H00000000 (black) and any bytes with &H00000000 (black) become &HFFFFFFFF (white), and of course with other data bytes being "bit flipped" regardless of the data they contain. This causes the image to look a bit like a "funny coloured negative" and of course if you flip the flipped image you end up with the original image you started with. Running the function any odd number of times will end up with a flipped image (hence his requirement of 1001 calls to the function rasther than 1000, so you can see the result). Running it 1001 times again will give you back the image you started with. > And can you give me a quick data = Not data> primer of the basic algorithm? Mike
Show quote
On Nov 29, 1:25 am, "Mike Williams" <mi***@whiskyandCoke.com> wrote: Ok...> "Tom Shelton" <tom_shel***@comcast.net> wrote in message > > news:e4a21924-00ea-4e34-83d4-4e252edc6594@e6g2000prf.googlegroups.com... > > > Mike... > > I'm not sure if Michael C will ever respond - but, I would be > > happy to have a go at a VB.NET version. The problem is > > I'm not a graphics guy, by any stretch of the imagination, and > > so I'm not sure what you mean by inverting the bitmap? > > Well I've taken it to mean flipping each bit in each data byte in the image, > so that for example any bytes with &HFFFFFFFF (white) become &H00000000 > (black) and any bytes with &H00000000 (black) become &HFFFFFFFF (white), and > of course with other data bytes being "bit flipped" regardless of the data > they contain. This causes the image to look a bit like a "funny coloured > negative" and of course if you flip the flipped image you end up with the > original image you started with. Running the function any odd number of > times will end up with a flipped image (hence his requirement of 1001 calls > to the function rasther than 1000, so you can see the result). Running it > 1001 times again will give you back the image you started with. > > > And can you give me a quick > > primer of the basic algorithm? > > data = Not data > > Mike VB.NET: Option Strict On Option Explicit On Imports System Imports System.Drawing Imports System.Drawing.Imaging Imports System.Runtime.InteropServices Imports System.Diagnostics Module Module1 Sub Main() Dim bmp As New Bitmap("blizz2001-1024.bmp") Dim sw As New Stopwatch() sw.Start() For i As Integer = 0 To 1000 ComplementImage(bmp) Next i Console.WriteLine(sw.Elapsed) bmp.Save("blizz2001-1024 inverted.bmp") End Sub Private Sub ComplementImage(ByVal bmp As Bitmap) Dim bmpData As BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), _ ImageLockMode.ReadWrite, _ bmp.PixelFormat) Dim ptr As IntPtr = bmpData.Scan0 For i As Integer = 0 To bmpData.Height - 1 For j As Integer = 0 To bmpData.Width - 1 Dim component As Byte = Marshal.ReadByte(ptr) Marshal.WriteByte(ptr, Not component) ptr = New IntPtr(ptr.ToInt32() + 3) Next ptr = New IntPtr(ptr.ToInt32() + (bmpData.Stride - bmpData.Width * 3)) Next bmp.UnlockBits(bmpData) End Sub End Module Release mode compile: 00:00:26.5968744 So, 26.6 seconds. C#: using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Imaging; using System.Diagnostics; namespace ConsoleApplication1 { class Program { static void Main ( string[] args ) { Bitmap bmp = new Bitmap ( "blizz2001-1024.bmp" ); Stopwatch sw = new Stopwatch (); sw.Start (); for ( int i = 0; i < 1001; i++ ) { CreateComplement ( bmp ); } Console.WriteLine ( sw.Elapsed ); bmp.Save ( "blizz2001-1024 inverted.bmp" ); } static void CreateComplement ( Bitmap bmp ) { BitmapData bmpData = bmp.LockBits ( new Rectangle ( 0, 0, bmp.Width, bmp.Height ), ImageLockMode.ReadWrite, bmp.PixelFormat ); unsafe { byte* ptr = (byte*)bmpData.Scan0; for ( int i = 0; i < bmpData.Height; i++ ) { for ( int j = 0; j < bmpData.Width; j++ ) { *ptr = (byte)( ~*ptr ); ptr += 3; } ptr += bmpData.Stride - bmpData.Width * 3; } } bmp.UnlockBits ( bmpData ); } } } Release mode compile: 00:00:00.7690147 Or about .8 seconds My system - Intel Core 2 Duo E6600, 4GB Memory, Windows Vista Ultimate 32-bit. -- Tom Shelton
Show quote
"Tom Shelton" <tom_shel***@comcast.net> wrote in message I don't know VB.Net so I can't see where you are setting the size of the news:acf61c8e-0ceb-43d3-abd1-73e2943f9eee@s8g2000prg.googlegroups.com... > VB.NET: > [snip] > Sub Main() > Dim bmp As New Bitmap("blizz2001-1024.bmp") > Dim sw As New Stopwatch() > sw.Start() > For i As Integer = 0 To 1000 > ComplementImage(bmp) '[routine snipped] > Next i > Console.WriteLine(sw.Elapsed) > bmp.Save("blizz2001-1024 inverted.bmp") > [snip] > So, 26.6 seconds. bitmap there? Can I take it that the code loads the existing bitmap ("blizz2001-1024.bmp") into memory and operates on that bitmap and that the size of the bitmap is 1024 x 768 pixels x 24 bit? Also, I cannot see where you are allowing for the padding bytes on bitmaps that do not align on "four byte" boundaries, for example a 1025 x 768 pixel bitmap, in which Michael C's requirement was that you should invert only the actual pixel data bytes and leave the padding byte or bytes untouched. Are you actually doing that? Also, is the same kind of thing happenning in the C# code (I don't use C). Is that also loading a 1024 x 768 x 24 bit bitmap and invereting the data bytes while leaving the padding bytes untouched? And can I take it that they both produce a correctly inverted image when they have finished? Anyway, whatever the case, now that you have posted some code (you certainly beat Michael C to it!) I might as well post my own. Here it is. Paste it into a VB Form containing a Picture Box and a Command Button and change the hard coded bmp name appropriately (to a 1024x768 24 bitmap on your own system)and compile to a native code exe with all advanced optimizations checked. As expected, it is much slower than your C# code, but much faster than your VB.Net code. Let me know what result you get on your own system. In fact this particular task is hampered by the fact that VB6's For / Next loop seems to be very poorly implemented, because almost all of the time is spent by VB messing about with the loop itself and only about 20 per cent of the time is spent actually reading the data and flipping it and putting it back, Nevertheless, it is still quite quick and it proves that VB6 is certainly not the "slouch" that Michael C thinks it is. Post back with your timing result for this code. I'm getting 6 seconds here on my machine compared to the 26.6 seconds you're getting in your VB.Net code on your own machine. Mike Option Explicit Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" (pDst As Any, _ pSrc As Any, ByVal ByteLen As Long) Private Declare Function VarPtrArray _ Lib "msvbvm60.dll" Alias "VarPtr" _ (Ptr() As Any) As Long Private Declare Function GetObject Lib "gdi32" _ Alias "GetObjectA" (ByVal hObject As Long, _ ByVal nCount As Long, lpObject As Any) As Long Private Declare Function timeGetTime _ Lib "winmm.dll" () As Long Private Declare Function timeBeginPeriod _ Lib "winmm.dll" (ByVal uPeriod As Long) As Long Private Declare Function timeEndPeriod _ Lib "winmm.dll" (ByVal uPeriod As Long) As Long Private Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type Private Type SAFEARRAYBOUND cElements As Long lLbound As Long End Type Private Type SAFEARRAY2D cDims As Integer fFeatures As Integer cbElements As Long cLocks As Long pvData As Long Bounds(0 To 1) As SAFEARRAYBOUND End Type Private Sub DoIt() Dim j As Long, k As Long, pic() As Long Dim sa As SAFEARRAY2D, bmp As BITMAP, pixRight As Long Dim oddBytes As Long Dim mask1 As Long, mask2 As Long GetObject Picture1.Picture, Len(bmp), bmp With sa .cbElements = 4 .cDims = 2 .Bounds(0).lLbound = 0 .Bounds(0).cElements = bmp.bmHeight .Bounds(1).lLbound = 0 .Bounds(1).cElements = bmp.bmWidthBytes \ 4 .pvData = bmp.bmBits End With CopyMemory ByVal VarPtrArray(pic), VarPtr(sa), 4 oddBytes = (bmp.bmWidth And 3&) * (bmp.bmBitsPixel \ 8&) If oddBytes <> 0 Then Select Case oddBytes Case 1 mask1 = &HFF&: mask2 = &HFFFFFF00 Case 2 mask1 = &HFFFF&: mask2 = &HFFFF0000 Case 3 mask1 = &HFFFFFF: mask2 = &HFF000000 End Select End If For k = 0 To UBound(pic, 2) For j = 0 To UBound(pic, 1) - 1 pic(j, k) = Not pic(j, k) Next j If oddBytes = 0 Then pic(j, k) = Not pic(j, k) Else pic(j, k) = (Not pic(j, k) And mask1) _ Or (pic(j, k) And mask2) End If Next k CopyMemory ByVal VarPtrArray(pic), 0&, 4 End Sub Private Sub Command1_Click() Dim t1 As Long, t2 As Long, n As Long Caption = "Doing 1001 runs. Please wait . . ." t1 = timeGetTime For n = 1 To 1001 DoIt Next n t2 = timeGetTime Caption = Format((t2 - t1) / 1000, "0.0") & " seconds." Picture1.Refresh End Sub Private Sub Form_Load() timeBeginPeriod 1 Picture1.Picture = LoadPicture("c:\temp\jessica1024.bmp") End Sub Private Sub Form_Unload(Cancel As Integer) timeEndPeriod 1 End Sub
Show quote
On Nov 29, 3:06 am, "Mike Williams" <mi***@whiskyandCoke.com> wrote: Yep. One of the System.Drawing.Bitmap constructors takes a file name> "Tom Shelton" <tom_shel***@comcast.net> wrote in message > > news:acf61c8e-0ceb-43d3-abd1-73e2943f9eee@s8g2000prg.googlegroups.com... > > > VB.NET: > > [snip] > > Sub Main() > > Dim bmp As New Bitmap("blizz2001-1024.bmp") > > Dim sw As New Stopwatch() > > sw.Start() > > For i As Integer = 0 To 1000 > > ComplementImage(bmp) '[routine snipped] > > Next i > > Console.WriteLine(sw.Elapsed) > > bmp.Save("blizz2001-1024 inverted.bmp") > > [snip] > > So, 26.6 seconds. > > I don't know VB.Net so I can't see where you are setting the size of the > bitmap there? Can I take it that the code loads the existing bitmap > ("blizz2001-1024.bmp") into memory and operates on that bitmap and that the > size of the bitmap is 1024 x 768 pixels x 24 bit? as a parameter. And blizz2001-1024.bmp is a 1024 x 768 x 24 bit bitmap I found on the internet to test with. > Also, I cannot see where Well, To be honest, I'm not really sure :) I'll have to play a little> you are allowing for the padding bytes on bitmaps that do not align on "four > byte" boundaries, for example a 1025 x 768 pixel bitmap, in which Michael > C's requirement was that you should invert only the actual pixel data bytes > and leave the padding byte or bytes untouched. Are you actually doing that? > Also, is the same kind of thing happenning in the C# code (I don't use C). > Is that also loading a 1024 x 768 x 24 bit bitmap and invereting the data > bytes while leaving the padding bytes untouched? bit with that and make sure it still works. >And can I take it that they Yes. I save the bitmap to when I'm done, just to make sure.> both produce a correctly inverted image when they have finished? Show quote > Anyway, whatever the case, now that you have posted some code (you certainly I will try and test this latter today - but it will have to be done on> beat Michael C to it!) I might as well post my own. Here it is. Paste it > into a VB Form containing a Picture Box and a Command Button and change the > hard coded bmp name appropriately (to a 1024x768 24 bitmap on your own > system)and compile to a native code exe with all advanced optimizations > checked. As expected, it is much slower than your C# code, but much faster > than your VB.Net code. Let me know what result you get on your own system. > In fact this particular task is hampered by the fact that VB6's For / Next > loop seems to be very poorly implemented, because almost all of the time is > spent by VB messing about with the loop itself and only about 20 per cent of > the time is spent actually reading the data and flipping it and putting it > back, Nevertheless, it is still quite quick and it proves that VB6 is > certainly not the "slouch" that Michael C thinks it is. Post back with your > timing result for this code. I'm getting 6 seconds here on my machine > compared to the 26.6 seconds you're getting in your VB.Net code on your own > machine. my older slower amd machine. It's the only machine I have that has all three environments :) I don't have VB6 installed on my Vista box. VB6 is definately not a slouch. I will say that this is not a task at which VB.NET excels. But, given that C# and VB.NET are both managed languages - it's safe to say that a .NET langauge doesn't have to be a slouch either. -- Tom Shelton Tom Shelton wrote:
> I will try and test this latter today - but it will have to be done on If you're not testing compiled apps, what's the real point? There's no other way to > my older slower amd machine. It's the only machine I have that has > all three environments :) I don't have VB6 installed on my Vista box. actually distribute something to a customer, afterall, and that's the only place such a performance measure matters. On Nov 29, 1:21 pm, "Karl E. Peterson" <k***@mvps.org> wrote: What? You know better then that. All .NET apps run as native code.> Tom Shelton wrote: > > I will try and test this latter today - but it will have to be done on > > my older slower amd machine. It's the only machine I have that has > > all three environments :) I don't have VB6 installed on my Vista box. > > If you're not testing compiled apps, what's the real point? There's no other way to > actually distribute something to a customer, afterall, and that's the only place > such a performance measure matters. > -- > .NET: It's About Trust! > http://vfred.mvps.org So, I'm not sure what your on about. -- Tom Shelton Tom Shelton wrote:
> On Nov 29, 1:21 pm, "Karl E. Peterson" <k***@mvps.org> wrote: I only responded like that because you said VB6 wasn't installed on the Vista box, >> Tom Shelton wrote: >>> I will try and test this latter today - but it will have to be done on >>> my older slower amd machine. It's the only machine I have that has >>> all three environments :) I don't have VB6 installed on my Vista box. >> >> If you're not testing compiled apps, what's the real point? There's no other >> way to actually distribute something to a customer, afterall, and that's the >> only place such a performance measure matters. > > What? You know better then that. All .NET apps run as native code. > So, I'm not sure what your on about. which made me wonder if you were testing *that* version in the IDE. I guess, in hindsight, what it meant was you were simply wanting to test on the same box you could tweak on?
Show quote
On Nov 29, 2:01 pm, "Karl E. Peterson" <k***@mvps.org> wrote: Yea. I have VB6 on my other box, so I was going to redo the timings> Tom Shelton wrote: > > On Nov 29, 1:21 pm, "Karl E. Peterson" <k***@mvps.org> wrote: > >> Tom Shelton wrote: > >>> I will try and test this latter today - but it will have to be done on > >>> my older slower amd machine. It's the only machine I have that has > >>> all three environments :) I don't have VB6 installed on my Vista box. > > >> If you're not testing compiled apps, what's the real point? There's no other > >> way to actually distribute something to a customer, afterall, and that's the > >> only place such a performance measure matters. > > > What? You know better then that. All .NET apps run as native code. > > So, I'm not sure what your on about. > > I only responded like that because you said VB6 wasn't installed on the Vista box, > which made me wonder if you were testing *that* version in the IDE. I guess, in > hindsight, what it meant was you were simply wanting to test on the same box you > could tweak on? > -- > .NET: It's About Trust! > http://vfred.mvps.org on that box. Don't worry. I will definately compile the VB6 app before testing. -- Tom Shelton Tom Shelton wrote:
Show quote > On Nov 29, 2:01 pm, "Karl E. Peterson" <k***@mvps.org> wrote: Cool. Sorry for questioning that...>> Tom Shelton wrote: >>> On Nov 29, 1:21 pm, "Karl E. Peterson" <k***@mvps.org> wrote: >>>> Tom Shelton wrote: >>>>> I will try and test this latter today - but it will have to be done on >>>>> my older slower amd machine. It's the only machine I have that has >>>>> all three environments :) I don't have VB6 installed on my Vista box. >> >>>> If you're not testing compiled apps, what's the real point? There's no other >>>> way to actually distribute something to a customer, afterall, and that's the >>>> only place such a performance measure matters. >> >>> What? You know better then that. All .NET apps run as native code. >>> So, I'm not sure what your on about. >> >> I only responded like that because you said VB6 wasn't installed on the Vista >> box, which made me wonder if you were testing *that* version in the IDE. I >> guess, in hindsight, what it meant was you were simply wanting to test on the >> same box you could tweak on? > > Yea. I have VB6 on my other box, so I was going to redo the timings > on that box. Don't worry. I will definately compile the VB6 app > before testing. "Tom Shelton" <tom_shel***@comcast.net> wrote in message other way tonews:bfe38413-d42b-48fc-b84f-be0d77dfb8aa@e23g2000prf.googlegroups.com... > On Nov 29, 1:21 pm, "Karl E. Peterson" <k***@mvps.org> wrote: > > Tom Shelton wrote: > > > I will try and test this latter today - but it will have to be done on > > > my older slower amd machine. It's the only machine I have that has > > > all three environments :) I don't have VB6 installed on my Vista box. > > > > If you're not testing compiled apps, what's the real point? There's no > > actually distribute something to a customer, afterall, and that's the I think Karl is simply saying that the /testing/ can be done on any box, andonly place > > such a performance measure matters. > > -- > > .NET: It's About Trust! > > http://vfred.mvps.org > > What? You know better then that. All .NET apps run as native code. > So, I'm not sure what your on about. > > -- need not have VB6 installed to do so. So a compiled app, with any required runtimes, should be able to run on any box for identical time testing, whether that app was compiled in VB6, VB.Net or C# (or whatever), and regardless of what environment or machine it was compiled on. -- Regards, Rick Raisley On Nov 29, 2:28 pm, "Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-
net> wrote: Show quote > "Tom Shelton" <tom_shel***@comcast.net> wrote in message Right - but I need to compile the source. So, it's convienient to> > news:bfe38413-d42b-48fc-b84f-be0d77dfb8aa@e23g2000prf.googlegroups.com... > > > > > > > On Nov 29, 1:21 pm, "Karl E. Peterson" <k***@mvps.org> wrote: > > > Tom Shelton wrote: > > > > I will try and test this latter today - but it will have to be done on > > > > my older slower amd machine. It's the only machine I have that has > > > > all three environments :) I don't have VB6 installed on my Vista box. > > > > If you're not testing compiled apps, what's the real point? There's no > other way to > > > actually distribute something to a customer, afterall, and that's the > only place > > > such a performance measure matters. > > > -- > > > .NET: It's About Trust! > > > http://vfred.mvps.org > > > What? You know better then that. All .NET apps run as native code. > > So, I'm not sure what your on about. > > > -- > > I think Karl is simply saying that the /testing/ can be done on any box, and > need not have VB6 installed to do so. So a compiled app, with any required > runtimes, should be able to run on any box for identical time testing, > whether that app was compiled in VB6, VB.Net or C# (or whatever), and > regardless of what environment or machine it was compiled on. > > -- > Regards, > > Rick Raisley- Hide quoted text - > > - Show quoted text - move it to my other box. I don't intend to install VB6 on my vista box :) -- Tom Shelton
Show quote
On Nov 29, 3:06 am, "Mike Williams" <mi***@whiskyandCoke.com> wrote: Ok. I tested yours compiled all advanced optimizations - and I get> "Tom Shelton" <tom_shel***@comcast.net> wrote in message > > news:acf61c8e-0ceb-43d3-abd1-73e2943f9eee@s8g2000prg.googlegroups.com... > > > VB.NET: > > [snip] > > Sub Main() > > Dim bmp As New Bitmap("blizz2001-1024.bmp") > > Dim sw As New Stopwatch() > > sw.Start() > > For i As Integer = 0 To 1000 > > ComplementImage(bmp) '[routine snipped] > > Next i > > Console.WriteLine(sw.Elapsed) > > bmp.Save("blizz2001-1024 inverted.bmp") > > [snip] > > So, 26.6 seconds. > > I don't know VB.Net so I can't see where you are setting the size of the > bitmap there? Can I take it that the code loads the existing bitmap > ("blizz2001-1024.bmp") into memory and operates on that bitmap and that the > size of the bitmap is 1024 x 768 pixels x 24 bit? Also, I cannot see where > you are allowing for the padding bytes on bitmaps that do not align on "four > byte" boundaries, for example a 1025 x 768 pixel bitmap, in which Michael > C's requirement was that you should invert only the actual pixel data bytes > and leave the padding byte or bytes untouched. Are you actually doing that? > Also, is the same kind of thing happenning in the C# code (I don't use C). > Is that also loading a 1024 x 768 x 24 bit bitmap and invereting the data > bytes while leaving the padding bytes untouched? And can I take it that they > both produce a correctly inverted image when they have finished? > > Anyway, whatever the case, now that you have posted some code (you certainly > beat Michael C to it!) I might as well post my own. Here it is. Paste it > into a VB Form containing a Picture Box and a Command Button and change the > hard coded bmp name appropriately (to a 1024x768 24 bitmap on your own > system)and compile to a native code exe with all advanced optimizations > checked. As expected, it is much slower than your C# code, but much faster > than your VB.Net code. Let me know what result you get on your own system. > In fact this particular task is hampered by the fact that VB6's For / Next > loop seems to be very poorly implemented, because almost all of the time is > spent by VB messing about with the loop itself and only about 20 per cent of > the time is spent actually reading the data and flipping it and putting it > back, Nevertheless, it is still quite quick and it proves that VB6 is > certainly not the "slouch" that Michael C thinks it is. Post back with your > timing result for this code. I'm getting 6 seconds here on my machine > compared to the 26.6 seconds you're getting in your VB.Net code on your own > machine. > > Mike > > Option Explicit > Private Declare Sub CopyMemory Lib "kernel32" _ > Alias "RtlMoveMemory" (pDst As Any, _ > pSrc As Any, ByVal ByteLen As Long) > Private Declare Function VarPtrArray _ > Lib "msvbvm60.dll" Alias "VarPtr" _ > (Ptr() As Any) As Long > Private Declare Function GetObject Lib "gdi32" _ > Alias "GetObjectA" (ByVal hObject As Long, _ > ByVal nCount As Long, lpObject As Any) As Long > Private Declare Function timeGetTime _ > Lib "winmm.dll" () As Long > Private Declare Function timeBeginPeriod _ > Lib "winmm.dll" (ByVal uPeriod As Long) As Long > Private Declare Function timeEndPeriod _ > Lib "winmm.dll" (ByVal uPeriod As Long) As Long > Private Type BITMAP > bmType As Long > bmWidth As Long > bmHeight As Long > bmWidthBytes As Long > bmPlanes As Integer > bmBitsPixel As Integer > bmBits As Long > End Type > Private Type SAFEARRAYBOUND > cElements As Long > lLbound As Long > End Type > Private Type SAFEARRAY2D > cDims As Integer > fFeatures As Integer > cbElements As Long > cLocks As Long > pvData As Long > Bounds(0 To 1) As SAFEARRAYBOUND > End Type > > Private Sub DoIt() > Dim j As Long, k As Long, pic() As Long > Dim sa As SAFEARRAY2D, bmp As BITMAP, pixRight As Long > Dim oddBytes As Long > Dim mask1 As Long, mask2 As Long > GetObject Picture1.Picture, Len(bmp), bmp > With sa > .cbElements = 4 > .cDims = 2 > .Bounds(0).lLbound = 0 > .Bounds(0).cElements = bmp.bmHeight > .Bounds(1).lLbound = 0 > .Bounds(1).cElements = bmp.bmWidthBytes \ 4 > .pvData = bmp.bmBits > End With > CopyMemory ByVal VarPtrArray(pic), VarPtr(sa), 4 > oddBytes = (bmp.bmWidth And 3&) * (bmp.bmBitsPixel \ 8&) > If oddBytes <> 0 Then > Select Case oddBytes > Case 1 > mask1 = &HFF&: mask2 = &HFFFFFF00 > Case 2 > mask1 = &HFFFF&: mask2 = &HFFFF0000 > Case 3 > mask1 = &HFFFFFF: mask2 = &HFF000000 > End Select > End If > For k = 0 To UBound(pic, 2) > For j = 0 To UBound(pic, 1) - 1 > pic(j, k) = Not pic(j, k) > Next j > If oddBytes = 0 Then > pic(j, k) = Not pic(j, k) > Else > pic(j, k) = (Not pic(j, k) And mask1) _ > Or (pic(j, k) And mask2) > End If > Next k > CopyMemory ByVal VarPtrArray(pic), 0&, 4 > End Sub > > Private Sub Command1_Click() > Dim t1 As Long, t2 As Long, n As Long > Caption = "Doing 1001 runs. Please wait . . ." > t1 = timeGetTime > For n = 1 To 1001 > DoIt > Next n > t2 = timeGetTime > Caption = Format((t2 - t1) / 1000, "0.0") & " seconds." > Picture1.Refresh > End Sub > > Private Sub Form_Load() > timeBeginPeriod 1 > Picture1.Picture = LoadPicture("c:\temp\jessica1024.bmp") > End Sub > > Private Sub Form_Unload(Cancel As Integer) > timeEndPeriod 1 > End Sub 9.3 seconds on my AMD Athlon 2000+ system with 1GB of ram. For my corrected C# (see Mike C's thread) I get 7.6 seconds. So, the C# is 1.7 seconds faster. I haven't had a chance to fix my VB.NET code - it is broken and I have a couple of optimizations in mind. I think I can optimize both even more to take advantage of my dual core processr and process the image in pieces on both cores - try that in VB6 :) (I know it can be done, but not easily). -- Tom Shelton "Tom Shelton" <tom_shel***@comcast.net> wrote in message Now this is getting interesting! :-)news:9bfb348b-e0b4-4bcb-ac38-d32434d63fbc@e6g2000prf.googlegroups.com... > Ok. I tested yours compiled all advanced optimizations - and I get > 9.3 seconds on my AMD Athlon 2000+ system with 1GB of ram. For my > corrected C# (see Mike C's thread) I get 7.6 seconds. So, the C# is > 1.7 seconds faster. I haven't had a chance to fix my VB.NET code - it > is broken and I have a couple of optimizations in mind. > > I think I can optimize both even more to take advantage of my dual > core processr and process the image in pieces on both cores - try that > in VB6 :) (I know it can be done, but not easily). Michael |
|||||||||||||||||||||||