Gustav Brock
Gustav at cactus.dk
Mon Oct 31 05:07:23 CST 2005
Hi Shamil I just read your post following this, and your conclusion about C# seems to be true. Your results from C++ is an eye-opener. I hardly can believe that speed improvement! But for a true comparison, could I persuade you to compile it to an DLL and call that from VB(A) the same way I did with the DLL compiled in FreeBASIC? You would probably need 10^7 loops or - if you measurement holds - 10^8 loops. /gustav >>> shamil at users.mns.ru 31-10-2005 09:40:17 >>> Hi Gustav, With switched off array bounds check and integer overflow check your sample code runs in less than 1 second when in VB6 bActiveX dll. Similar code in C++(VS.NET 2003) runs instantaneously. C++ allows to measure time when 10^6 cycles are additionally cycled 10^7 times! Below is sample C++ code. Maybe I did make some mistakes - 10^7 * 10^6 loops in just two seconds looks incredible speed gain under C++ - these are 989,999,010,000,000 cycles... And in 19 seconds 9,899,990,100,000,000 cycles can be executed. long ArrayTimeLocal(long lngLoopMax, long& lngTotalCnt); int _tmain(int argc, _TCHAR* argv[]) { long dblStart; long dblStop; long lngResult; long lngCnt = 0; __int64 totalCnt = 0; time(&dblStart); for (int i = 1; i<=10000000; i++) { lngResult = ArrayTimeLocal(1000000, lngCnt); totalCnt += ((__int64)lngCnt); if ((i % 1000000) == 0) printf("Result = %ld, Counter = %I64d\n", lngResult, totalCnt); } time(&dblStop); lngResult = (long)difftime(dblStop,dblStart); printf("Final Result = %ld, Final Counter = %I64d\n", lngResult, totalCnt); } long ArrayTimeLocal(long lngLoopMax, long& lngTotalCnt) { const long lngItems = 100; long alngTmp[lngItems-1][1]; long lngLoop; long lngItem; long lngResult; long lngSeconds; long dblStart; long dblStop; lngTotalCnt = 0; time(&dblStart); for (lngLoop=1; lngLoop < lngLoopMax; lngLoop++) { for (lngItem=1; lngItem < lngItems; lngItem++) { alngTmp[lngItem-1][0] = lngLoop * 10; if (alngTmp[lngItem-1][0] / 10 == 100) lngResult = 1; else lngResult = 0; lngTotalCnt++; } } time(&dblStop); lngSeconds = (long)difftime(dblStop,dblStart); return lngSeconds; } And here is result of this code test run: Result = 0, Counter = 98999901000000 Result = 0, Counter = 197999802000000 Result = 0, Counter = 296999703000000 Result = 0, Counter = 395999604000000 Result = 0, Counter = 494999505000000 Result = 0, Counter = 593999406000000 Result = 0, Counter = 692999307000000 Result = 0, Counter = 791999208000000 Result = 0, Counter = 890999109000000 Result = 0, Counter = 989999010000000 Final Result = 2, Final Counter = 989999010000000 Shamil