Just having to test out the raw speed and power of PBCC to see how fast it is and just find a use for having massive arrays, I create the following program. If this doesn't prove the raw speed of PowerBasic, nothing will! On my laptop just 4 seconds to sort an array of 5,000,001 and calculate the average number, minimum and maximum numbers..... I originally had it printing out all 5000001 numbers to the screen, but even printing as fast as possible, it still took too long to print....
Here's The code....
5,867,433,384 Ticks (3 seconds) on this run....
Here's The code....
Code:
#COMPILE EXE #DIM ALL #BREAK ON SUB FastPrint(Str AS STRING) PAGE 2,1 PRINT Str; PCOPY 2,1 PAGE 1,1 END SUB SUB FastPrintLn(Str AS STRING) PAGE 2,1 PRINT Str PCOPY 2,1 PAGE 1,1 END SUB FUNCTION PBMAIN () AS LONG DIM Ar(5000000) AS DWORD DIM t AS DWORD DIM X AS DWORD DIM y AS DWORD DIM avg AS DWORD DIM Total AS DWORD DIM Mx AS DWORD DIM First AS INTEGER DIM Ticker AS QUAD RANDOMIZE -TIMER COLOR 15 CALL FastPrintLn(REPEAT$(8,"<)-=[]=-(>")) First = TIMER TIX Ticker Mx = UBOUND(Ar()) FOR T = 0 TO Mx Ar(T) = RND(1,Mx) NEXT COLOR 11 CALL FastPrintLn("Array Created and Populated with " + USING$("###,###,###,###",Mx + 1) + " Elements.") COLOR 12 CALL FastPrint("Sorting....") ARRAY SORT Ar() COLOR 10 CALL FastPrintLn("Done!") COLOR 7 CALL FastPrint("Averaging Data...") Total = 0 FOR T = 0 TO Mx Total = Total + Ar(T) NEXT T Avg = Total / Mx COLOR 9 CALL FastPrintLn("Done!") CALL FastPrintLn("") CALL FastPrintLn("") COLOR 15 PAGE 1,1 PRINT PRINT CALL FastPrintLn(REPEAT$(10,"<)-[]-(>")) PRINT COLOR 11 CALL FastPrintLn("Average = " + Upbfo$("###,###,###,###",Avg)) CALL FastPrintLn("Total = " + USING$("###,###,###,###",Total)) CALL FastPrintLn("Minimum = " + USING$("###,###,###,###",Ar(0))) CALL FastPrintLn("Maximum = " + USING$("###,###,###,###",Ar(Mx))) CALL FastPrintLn("Time = " + USING$("###,###,###,###",(TIMER - First)) + " Second(s).") TIX END Ticker CALL FastPrintLn("Ticks = " + USING$("###,###,###,###",Ticker)) COLOR 10 CALL FastPrintLn("Press Any Key To Continue...") PROFILE "JohnProfile.txt" WAITKEY$ END FUNCTION