Sorting And Searching

Anything QL Software or Programming Related.
User avatar
janbredenbeek
Super Gold Card
Posts: 629
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Sorting And Searching

Post by janbredenbeek »

tcat wrote:Ah, that explains that nicely. So what QL does is actually clever, keeping select & loop variables in FP, that way is faster in the interpreter.
Real benefit of integers is perhaps smaller space allocated on stack or heap, as TG says, integers take words, floats take exponent(word)+mantisa(long), i.e. 2bytes versus 6bytes.
Integer arithmetic is always faster if done properly. The problem is that SuperBASIC stores constants as float, so when you do i%=i%+1 it first has to convert i% to float, add 1 using float arithmetic, then convert the new value back to integer and store it in i%, which is of course a waste of time. Minerva solved this by introducing integer tokenisation so that constants which will fit into an integer are indeed stored as integer so no conversion to float is needed when doing arithmetic (unless you get overflow or mix them with floats of course). Thus, on Minerva, programs which use lots of integer arithmetic will run a little faster and take up less space (notably with lots of numeric DATA statements).
With the storage and processing power currently available, there probably isn't much to be gained from using integers. Modern processors have integrated FP arithmetic capabilities and even if emulators like QPC2 wouldn't make use of them the speed penalty would probably not be noticable.

Jan.


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: Sorting And Searching

Post by stevepoole »

Hi Dden,
How long a list of words do you wish to sort?
My 'ROOT' SuperBasic stringsort program can handle lists of 32766 words, which it sorts in 13 seconds under QPC2 at 1.8Ghz.
Compiled it is much faster. It could be compiled with its IMPLICIT% pointer array to run faster still.
I am currently optimising it, but can let you have it via a private message, then I will email it as an attatchment.
You will have to adapt it for your array input, which is just a question of renaming the program array to your array name in one instruction...
It can sort words of 1 to many characters, using standard QL string comparisons.
I have used it for 30 years without a hitch. (It has also been used by professionals).
It is included in a demo, so you can time it if you wish.
For tinkerers...
Regards,
Steve Poole.


User avatar
dden
ROM Dongle
Posts: 43
Joined: Thu Jan 19, 2017 8:56 am

Re: Sorting And Searching

Post by dden »

stevepoole wrote:Hi Dden,
How long a list of words do you wish to sort?
My 'ROOT' SuperBasic stringsort program can handle lists of 32766 words, which it sorts in 13 seconds under QPC2 at 1.8Ghz.
Compiled it is much faster. It could be compiled with its IMPLICIT% pointer array to run faster still.
I am currently optimising it, but can let you have it via a private message, then I will email it as an attatchment.
You will have to adapt it for your array input, which is just a question of renaming the program array to your array name in one instruction...
It can sort words of 1 to many characters, using standard QL string comparisons.
I have used it for 30 years without a hitch. (It has also been used by professionals).
It is included in a demo, so you can time it if you wish.
For tinkerers...
Regards,
Steve Poole.
Up to the maximum size of a QL string array.
I'll send the private message now, it might take a while as I've never used them before.

Thanks to Tomas too for his nice little routine.

Still looking for a wildcard routine if you have anything in that department.


David
Post Reply