[AccessD] Array faster in DLL?

Shamil Salakhetdinov shamil at users.mns.ru
Mon Oct 31 04:34:11 CST 2005


Gustav,

I think if you say that you have forgotten 99% Fortran then you can convert
your code into C++ with same efforts as on Fortran.  I mean  - if your
code is just "arrays shuffling" as you say then VB(A)-> C++ conversion is
almost line by line...

I did recheck - your code runs just in 5 seconds on VB6 with array bounds
checks and integer overflow checks switched off. These are 100,000,000
loops.

I did also test your sample code on C# and VB.NET - and it runs in 5-6
seconds
with switched off integer overflow checks (it looks that there is no way to
switch off array bounds checks for C# and VB.NET) .

Here is VB.NETcode I used for testing:

VB.NET
-----------
Module testArrays

    Sub Main()
        Dim lngResult As Long = 0
        Dim lngCnt As Long = 0
        Dim lngTotalCnt As Long = 0
        lngResult = ArrayTimeLocal(1000000, lngTotalCnt)
        lngTotalCnt += lngCnt
        Console.WriteLine(String.Format( _
         "Final Result = {0:#,##0}, Final Counter = {1:#,##0}", _
         lngResult, lngTotalCnt))
    End Sub

    Function ArrayTimeLocal(ByVal lngLoopMax As Long, ByRef lngTotalCnt As
Long) As Long

        Const lngItems As Long = 100

        Dim alngTmp(lngItems - 1, 1) 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
        Dim lngCnt As Long = 0
        dblStart = Timer

        For lngLoop = 0 To lngLoopMax - 1
            For lngItem = 0 To lngItems - 1
                alngTmp(lngItem, 1) = lngLoop * 10
                If alngTmp(lngItem, 1) / 10 = 100 Then
                    lngResult = 1
                Else
                    lngResult = 0
                End If
                lngCnt += 1
            Next
        Next

        dblStop = Timer
        lngSeconds = CLng(dblStop - dblStart)

        lngTotalCnt = lngCnt
        ArrayTimeLocal = lngSeconds

    End Function

End Module

Output
----------
Final Result = 5, Final Counter = 100,000,000

C#
===
using System;
using Microsoft.VisualBasic;

namespace testArraysCS
{
 class TestArrays
 {
  [STAThread]
  unsafe static void Main(string[] args)
  {
   long lngTotalCnt = 0;
   long lngResult = 0;

   lngResult = ArrayTimeLocal(1000000, ref lngTotalCnt);
   Console.WriteLine(String.Format(
    "Final Result = {0:#,##0}, Final Counter = {1:#,##0}",
    lngResult, lngTotalCnt));
  }

  unsafe static long ArrayTimeLocal(long lngLoopMax, ref long lngTotalCnt) {
   const long lngItems = 100;
   long[,] alngTmp = new long[lngItems,1] ;
   long lngLoop;
   long lngItem;
   long lngResult=0;
   double dblStart;
   double dblStop;
   long lngSeconds;

   Console.WriteLine("Array looping test started...");
   dblStart = Microsoft.VisualBasic.DateAndTime.Timer;
   lngTotalCnt = 0;
   for (lngLoop=0; lngLoop < lngLoopMax; lngLoop++) {
    for (lngItem=0; lngItem < lngItems; lngItem++) {
     alngTmp[lngItem,0] = lngLoop * 10;
     if (alngTmp[lngItem,0] / 10 == 100) lngResult = 1;
     else lngResult = 0;
     lngTotalCnt++;
    }
   }
   dblStop = Microsoft.VisualBasic.DateAndTime.Timer;
   Console.WriteLine("Array looping test ended.");
   lngSeconds = (long)(dblStop - dblStart);
   return lngSeconds;
  }

 }
}

Output
---------
Array looping test started...
Array looping test ended.
Final Result = 6, Final Counter = 100,000,000

Recapitulation:
===========

C++ & Fortran (and COBOL?) rule and rock forever! :)

Shamil

----- Original Message ----- 
From: "Gustav Brock" <Gustav at cactus.dk>
To: <accessd at databaseadvisors.com>
Sent: Monday, October 31, 2005 11:51 AM
Subject: Re: [AccessD] Array faster in DLL?


> Hi Marty
>
> Thanks! For those of you working with dot net note that this compiler
(also) integrates with Visual Studio.
> However, it is so many years since I touched Fortran as a happy student
that I have forgotten it 99%.
> It certainly looks like a perfect choice for heavy floating point
operations - which I don't need - at a fair cost.
>
> It could be interesting to see how the computing time would be in VB(A)
for the sinus approximation sample here:
>
>
http://www.intel.com/software/products/compilers/fwin/docs/Getting_Started.htm
>
> /gustav
>
> >>> martyconnelly at shaw.ca 30-10-2005 22:37:35 >>>
> Oopps here is the url
> For Intel Fortran  Note: it also optimizes on array loops for parallel
> processing assuming multi cores.
>
>
http://www.intel.com/cd/software/products/asmo-na/eng/compilers/fwin/219725.htm
>
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com




More information about the AccessD mailing list