Shamil Salakhetdinov
shamil at users.mns.ru
Mon Oct 31 06:56:42 CST 2005
With variables moved to (static) memory out of stack the code works for ~6
seconds slower (yes, that was stupid of me to expect it running faster -
when getting/putting variable from/to stack Intel processors should work
faster). Well, one can see 6 seconds difference on 10,000,000,000 cycle runs
only - for usual programming this difference doesn't matter. Here is C++
sample code, which runs 19 seconds on my PC:
#include "stdafx.h"
#include <time.h>
typedef long COUNTER_TYPE;
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;
COUNTER_TYPE lngCnt;
static long ArrayTimeLocal(long lngLoopMax, COUNTER_TYPE& lngTotalCnt, bool
useTracePrinting = false);
int _tmain(int argc, _TCHAR* argv[])
{
_int64 lngTotalCnt = 0;
COUNTER_TYPE lngCnt = 0;
time_t /*double*/ dblStart;
time_t /*double*/ dblStop;
long lngSeconds = 0;
time(&dblStart);
for (int i=1; i<=100; i++) {
ArrayTimeLocal(1000000, 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, COUNTER_TYPE& lngTotalCnt, bool
useTracePrinting) {
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;
}
Shamil
----- Original Message -----
From: "Shamil Salakhetdinov" <shamil at users.mns.ru>
To: "Access Developers discussion and problem solving"
<accessd at databaseadvisors.com>
Sent: Monday, October 31, 2005 3:22 PM
Subject: Re: [AccessD] Array faster in DLL?
> 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
>
<<< tail skipped>>>