Re: The inaugural VB6 vs dot net test
- From: Ulrich Korndoerfer <ulrich_wants_nospam@xxxxxxxxxxxx>
- Date: Sat, 01 Dec 2007 03:25:11 +0100
Hi again,
Did some obvious improvements on Invert3 and changed the loop direction in Invert1 back to counting from 0 up. Counting down actually is slower. Now both methods are equally fast. Invert3 respects padding bits, but is optimized for 24bpp, Invert1 is more general regarding the bpp, but changes padding bits.
/////
// New test results
/////
Compiled to native code, settings are:
"Compile for speed, use *all* extended optimizations"
Intel Core 2 Duo @ 1.86 GHz
1024 x 768 bitmap, 24 bits per pixel
1001 iterations per run, 3 runs
Invert1: 1.504, 1.508, 1.505 sec
Invert3: 1.503, 1.502, 1.504 sec
/////
// Improved test methods (in a module)
/////
Private Sub Invert1(ByVal PictureHandle As Long)
Dim sa As SAFEARRAY2D, BM As BITMAP
Dim LPtr() As Long, BPtr() As Byte
Dim i As Long, NotLongMappableByteCount As Long
Dim LongCount As Long
gBitmapDataFromPictureHandle PictureHandle, BM
i = BM.bmHeight * BM.bmWidthBytes
NotLongMappableByteCount = i And &H3
LongCount = (i - NotLongMappableByteCount) \ 4&
gMakePtr gArrPtr(LPtr), sa, 4, BM.bmBits
For i = 0 To LongCount - 1
LPtr(i) = Not LPtr(i)
Next i
gDestroyPtr gArrPtr(LPtr)
If NotLongMappableByteCount = 0 Then Exit Sub
gMakePtr gArrPtr(BPtr), sa, 1, BM.bmBits + 4 * LongCount
For i = 0 To NotLongMappableByteCount - 1
BPtr(i) = Not BPtr(i)
Next i
gDestroyPtr gArrPtr(BPtr)
End Sub
Private Sub Invert3(ByVal PictureHandle As Long)
Dim sa As SAFEARRAY2D, BM As BITMAP
Dim LPtr() As Long, BPtr() As Byte
Dim k As Long, MaxIndex As Long
Dim Mask As Long, ExcessBytes As Long
gBitmapDataFromPictureHandle PictureHandle, BM
k = BM.bmWidth * 3&
MaxIndex = k \ 4&
ExcessBytes = k - MaxIndex * 4&
Select Case ExcessBytes
Case 1: Mask = &HFF
Case 2: Mask = &HFFFF
Case 3: Mask = &HFFFFFF
End Select
MaxIndex = MaxIndex - 1
gMakePtr gArrPtr(LPtr), sa, 4, 0
For sa.pvData = BM.bmBits _
To BM.bmBits + (BM.bmHeight - 2) * BM.bmWidthBytes _
Step BM.bmWidthBytes
For k = 0 To MaxIndex
LPtr(k) = Not LPtr(k)
Next k
If ExcessBytes <> 0 Then LPtr(k) = LPtr(k) Xor Mask
Next sa.pvData
For k = 0 To MaxIndex
LPtr(k) = Not LPtr(k)
Next k
gDestroyPtr gArrPtr(LPtr)
If ExcessBytes = 0 Then Exit Sub
gMakePtr gArrPtr(BPtr), sa, 1, sa.pvData + k * 4&
For k = 0 To ExcessBytes - 1
BPtr(k) = Not BPtr(k)
Next k
gDestroyPtr gArrPtr(BPtr)
End Sub
--
Ulrich Korndoerfer
VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
.
- Follow-Ups:
- Re: The inaugural VB6 vs dot net test
- From: Mike Williams
- Re: The inaugural VB6 vs dot net test
- References:
- Re: The inaugural VB6 vs dot net test
- From: Ulrich Korndoerfer
- Re: The inaugural VB6 vs dot net test
- Prev by Date: Re: Dumb question about AppId, CLSID and GUID...
- Next by Date: Re: Dumb question about AppId, CLSID and GUID...
- Previous by thread: Re: The inaugural VB6 vs dot net test
- Next by thread: Re: The inaugural VB6 vs dot net test
- Index(es):
Relevant Pages
|
Loading