[AccessD] Array faster in DLL?

Gustav Brock Gustav at cactus.dk
Sun Oct 30 14:16:19 CST 2005


Hi Marty, Shamil, Fred et all

Well, I did a small and quite surprising test inspired by Shamil.
Here is a test routine which can be seen as typical for what I do.
The array is not large but it is read from and written to a bunch of times.

Here is the local test using standard VBA:

Function ArrayTimeLocal(ByVal lngLoopMax As Long) As Long
    
  Const lngItems                      As Long = 100
  
  Dim alngTmp(1 To lngItems, 1 To 2)  As Long
  Dim lngLoop                         As Long
  Dim lngItem                         As Long
  Dim lngResult                       As Long
  Dim lngSeconds                      As Long
  Dim dblStart                        As Double
  Dim dblStop                         As Double

  dblStart = Timer
  
  For lngLoop = 1 To lngLoopMax
    For lngItem = 1 To lngItems
      alngTmp(lngItem, 1) = lngLoop * 10
      If alngTmp(lngItem, 1) / 10 = 100 Then
        lngResult = 1
      Else
        lngResult = 0
      End If
    Next
  Next
  
  dblStop = Timer
  lngSeconds = CLng(dblStop - dblStart)
    
  ArrayTimeLocal = lngSeconds
    
End Function

And this is the test function using an DLL containing nearly identical code:

Declare Function ArrayTime Lib "arraydll.dll" Alias "ArrayTime at 4" (ByVal lngLoops As Long) As Long

Function ArrayTimeDLL(ByVal lngLoopMax As Long) As Long

  ArrayTimeDLL = ArrayTime(lngLoopMax)

End Function

The DLL was programmed and compiled in FreeBASIC and the FBIde which I earlier posted links for.

Setting lngLoopMax to 10^6 returns these running times for the two functions:

  ArrayTimeLocal: 34 seconds
  ArrayTimeDLL: 2.2 seconds (measured with 10^7 loops)

Thus this simple tool gives a speed improvement of 15.5 to 1 ... not bad!

Nothing comes free, and the trouble is - as far as I can see - that the dll has to be programmed to run rock stable. If it errors out, Access halts or simply quits - no errors, no GPF, just poof away.

With this result I think I'll leave the assembler stuff for now. Still, if anyone with PowerBasic or other compiler could make similar tests and publish the results, we could rank these.

/gustav


>>> martyconnelly at shaw.ca 30-10-2005 20:08 >>>
Personally if I am using arrays or a lot of matrix math like Fourier Transforms. I develop in Intel Fortran Compiler for Windows & Visual Fortran  but I can write Fortran in my sleep.
It is COM compliant and callable from VBA. I have written DOS assembler a long time ago what I could do in a day in Fortran would take me 6 weeks in assembler just because I would have to relearn so much. Microsoft VB with arrays has a lot of overhead of error, type and range checking.
Come to think of it IBM Fortran compilers and maybe others used to produce an optional ASM listing that might help you out.

MartyConnelly wrote:

>If you are working with really for sure definetely absolutely fixed size 
>arrays in VB6 dll you can
>turn off Remove Array Bounds Checks option for about 25% speed 
>performance increase.
>With the chance of a GPF





More information about the AccessD mailing list