Shamil Salakhetdinov
shamil at users.mns.ru
Mon Oct 31 06:22:23 CST 2005
Gustav,
Yes, I can make a C++ dll but maybe you first (re)define your test function
call interface because even if you call very quick C++ function 1000 times
from VB6 you can loose all the advantages this C++ function gives.
Currently - here is C++ (non managed) console applications results for a
function similar to yours:
10,000,000,000 your cycles in 13 seconds (ot looks like I did some mistakes
in my previous time calculations - I have to recheck)
=====================================
Final Result = 13, Final Counter = 10000000000
=====================================
Here is the C++ code for the last test:
#include "stdafx.h"
#include <time.h>
static long ArrayTimeLocal(long lngLoopMax, long& lngTotalCnt, bool
useTracePrinting = false);
int _tmain(int argc, _TCHAR* argv[])
{
_int64 lngTotalCnt = 0;
long lngCnt = 0;
time_t /*double*/ dblStart;
time_t /*double*/ dblStop;
long lngSeconds = 0;
time(&dblStart);
for (int i=1; i<=10; i++) {
ArrayTimeLocal(10000000, lngCnt);
lngTotalCnt += lngCnt;
}
time(&dblStop);
lngSeconds = (long)difftime(dblStop,dblStart);;
printf("Final Result = %ld, Final Counter = %I64d\n",
lngSeconds, lngTotalCnt);
}
static long ArrayTimeLocal(long lngLoopMax, long& lngTotalCnt, bool
useTracePrinting) {
const long lngItems = 100;
long alngTmp[lngItems][2];
long lngLoop;
long lngItem;
long lngResult = 0;
time_t /*double*/ dblStart;
time_t /*double*/ dblStop;
long lngSeconds;
long lngCnt = 0;
if (useTracePrinting) printf("Array looping test started..\n");
time(&dblStart);
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;
lngCnt++;
}
}
time(&dblStop);
if (useTracePrinting) printf("Array looping test ended.\n");
lngSeconds = (long)difftime(dblStop,dblStart);;
if (useTracePrinting) printf("Result = %lf, Counter = %ld\n",
lngSeconds, lngTotalCnt);
lngTotalCnt = lngCnt;
return lngSeconds;
}
I will try to move now all variable from stack to static memory - I expect
it may bring even more speed execution gains. We will see.
As soon as you define your final call interface I will make a test C++
.dll...
Shamil
----- Original Message -----
From: "Gustav Brock" <Gustav at cactus.dk>
To: <accessd at databaseadvisors.com>
Sent: Monday, October 31, 2005 2:56 PM
Subject: Re: [AccessD] Array faster in DLL?
> Hi Shamil
>
> Oh my ... could you create a DLL with the essentials from your
ArrayTimeLocal skipping the console parts? It just need to return the
lngSeconds.
>
> Looks like I need some C++ stuff for this project!
>
> /gustav
>
> >>> shamil at users.mns.ru 31-10-2005 12:17:09 >>>
> Gustav,
>
> And finally here is managed C++, which runs instantaneously:
>
> #include "stdafx.h"
>
> #using <mscorlib.dll>
> #using <Microsoft.VisualBasic.dll>
>
> using namespace System;
>
> static long ArrayTimeLocal(long lngLoopMax, long& lngTotalCnt);
> int _tmain()
> {
> long lngTotalCnt = 0;
> long lngResult = 0;
>
> lngResult = ArrayTimeLocal(1000000, lngTotalCnt);
> Console::WriteLine(String::Format(
> S"Final Result = {0:#,##0}, Final Counter = {1:#,##0}",
> __box(lngResult), __box(lngTotalCnt)));
> }
>
> static long ArrayTimeLocal(long lngLoopMax, long& lngTotalCnt) {
> const long lngItems = 100;
> long alngTmp[lngItems-1][2];
> 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 = 0, Final Counter = 100,000,000
>
> And it takes ~18 seconds on my PC to run this test ADDITIONALLY looped 100
> times....
>
> Shamil
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com