Awesome we need these kind of samples Eros, thanks so much. You might want to talk with Roberto, he had an interesting idea of placing all of these in a repository so easy to find.
Sorting numeric arrays?
Using built-in sorting functions it can take ... no time.
'---Globals DIM MaxCount AS LONG value 100000 dim MyArray(MaxCount) as long dim Count as long dim T1, T2 as double DIM Message AS STRING '---Ask if execute or not Message = "This program will fill an array of " & MaxCount & " elements with random LONG numbers.\n" Message += "Array will be sorted twice in order to test sorting of sparse and already sorted array.\n\n" Message += "Please press Yes to go on, NO to Stop\n" DIM lResult AS LONG = MSGBOX(0, Message, %MB_YESNO, "Continue?") IF lResult <> %IDYES THEN STOP END IF '---Speed up operations a bit doevents(off) '---Init random number generator randomize '---Fill array with random numbers T1 = GetTickCount for Count = LBound(MyArray) To UBound(MyArray) MyArray(Count) = rnd(-1000000000, 1000000000) next T2 = GetTickCount '---Do the job msgbox 0, _ "Time to fill randomly an array of " & ubound(MyArray) & " elements:" & $tab & format$(T2-T1) & " mSecs" & $crlf & _ "Time to sort array " & repeat$(5, $tab) & testsort(MyArray) & " mSecs" & $crlf & _ "Time to re-sort sorted array " & repeat$(4, $tab) & testsort(MyArray) & " mSecs" & $crlf & _ "Time to re-sort sorted array in descending order " & repeat$(2, $tab) & testsort(MyArray, %TRUE) & " mSecs" & $crlf & _ "" '---------------------------------------------------------------------------- '---In case you want to see some output values, just uncomment those lines '---------------------------------------------------------------------------- 'uses "console" 'for count = 1 to 80 ' console_write MyArray(Count) & ", " 'next 'console_waitkey '---------------------------------------------------------------------------- '---Sorting function '---------------------------------------------------------------------------- Function TestSort(byref v() as long, optional DeScendSorting as long) as long '---Time measuring vars local ticka, tickb as double '---Start timer ticka = GetTickCount '---Sort array passed by reference depending on sort order if DeScendSorting = %TRUE then array sort v, descend else array sort v end if '---ENd timer tickb = GetTickCount function = tickb - ticka End Function
Last edited by ErosOlmi; 21-02-2024 at 21:35.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Awesome we need these kind of samples Eros, thanks so much. You might want to talk with Roberto, he had an interesting idea of placing all of these in a repository so easy to find.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Repository is already there at http://scripts.thinbasic.com/ but abandoned.
I did it almost one year ago but at that time it was not the right time.
I will consider your wiki suggestion checking which is the best around.
I want it easy to be used and with syntax highlight.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Bookmarked, never saw it or don't remember that. I would sticky that to the top or put in the menubar on the forums for sure. Great!!
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Ken,
we are not maintaining it anymore.
I will delete it and substitute with a new one after choosing the best we can find.
So continue your suggestion about wiki. I will follow it and in the meantime try to find what will be better for thinBasic community.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Have you considered using a wiki for maintaining and sharing these code samples for the thinBasic community, as suggested by kryton9?
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Bookmarks