SBASIC & C++

Anything QL Software or Programming Related.
Post Reply
swensont
Forum Moderator
Posts: 252
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

Re: SBASIC & C++

Post by swensont »

> I would rather say that QPC is indeed fully optimised for all the software that has been written
> for the QL so far.

There is a fair bit of software written in the early days of the QL that will not run on QPC or other emulators. Heck, some won't run on anything but a QL with 128K ram. Add a Gold Card and the software will fail. This software was written assuming that the screen will be at a certain location, or that memory will not change, etc. That was all the point I was making.


User avatar
tofro
Font of All Knowledge
Posts: 2700
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: SBASIC & C++

Post by tofro »

Just a short one in case anyone is still interested in speed comparisons:

An (optimized) "Sieve of Erastothenes" program that calculates primes up to 200000 runs in

pure S*Basic on QPC2: 15s
Turbo compiled: 6s
translated to C and C68-compiled: 2s

And just for comparison Q-Liberated: 13s

The tests were run on my pretty fast MacBook. It would be interesting to know how long it takes on original SuperBASIC - I would guess well over several minutes. I simply don't have a working QL handy just now.

Quite a bit of the time spent is lost in screen output (so I guess C would even be faster....), and overall the test is not very fair for various reasons, but you can see the difference.

Sources attached - They should also give a bit of an idea how the same program (I tried to keep them as close as possible) looks in Basic and C.

Tobias

Code: Select all

 #define N 200000

 #include <stdio_h>
 #include <math_h>
 #include <stdlib_h>
 #include <time_h>

 char *crossed;
 long i, j, k;

 void main () {
    time_t t;
    t = time (NULL);
    crossed = calloc (N, 1);

    for (i = 2; i < sqrt(N); i++) {
       if (!*(crossed + i)) {
          printf ("%d, ", i);
          for (j = i*i; j < N; j+=i) {
             *(crossed + j) = 1;
          }
       }
    }

    for (i = sqrt(N) + 1; i < N; i++) {
       if (!*(crossed + i)) {
          printf("%d, ", i);
       }
    }
    printf("Primes to %d calculated in %d seconds", N, time (NULL) - t);
}

Code: Select all

10 a = DATE
100  DEF_INTEGER i,j
110  MANIFEST: n = 200000
120  crossed = ALCHP (n)
140  FOR i = 1 TO n
150    POKE crossed+i, 0
160  END FOR i
180  REMark sieve
190  FOR i = 2 TO SQRT(n)
200    IF PEEK(crossed+i) = 0 THEN
210      PRINT i; ", ";
220      FOR j = i * i TO n STEP i
230        POKE crossed+j, 1
240      END FOR j
250    END IF
260  END FOR i
280  FOR i = INT(SQRT(n)) + 1 TO n
290    IF PEEK(crossed +i) = 0
300      PRINT i; ", ";
310    END IF
320  END FOR i
330 PRINT :PRINT "Primes to ";n;" calculated in "; DATE - a; " seconds"
335 PAUSE -1
337 RECHP crossed
340  STOP


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
stevepoole
Super Gold Card
Posts: 714
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Thanks everyone. Now I can clearly see what needs doing. So work on the TSP will definitely proceed, as it looks like it already has quite good performance, running on a 2.8+ Ghz PC under QPC2. But that will have to wait until mid-january, as I am in the meantime fully occupied with other things.

Some people have already received a copy of versions of the program. It is at present 6Ko long and will be submitted to Quanta for publication towards the end of january, after further optimisation.
I have the offer of by a C professional programmer to transcode it into C++ thereafter.

Good luck with your projects...
Steve.


User avatar
pjw
QL Wafer Drive
Posts: 1299
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: SBASIC & C++

Post by pjw »

Tobias,

What is the DEF_INTEGER on line 100 for?

Per


Per
dont be happy. worry
- ?
User avatar
NormanDunbar
Forum Moderator
Posts: 2274
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SBASIC & C++

Post by NormanDunbar »

Hi Per,
pjw wrote:Tobias,

What is the DEF_INTEGER on line 100 for?

Per
If I remember my Turbo correctly, Def Integer means that those variables will be treated as integers and not floating point. Handy for pre SMS* QLs that can't do integer FOR loops, for example.

Should run quicker, I think. But that depends on the code obviously.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
NormanDunbar
Forum Moderator
Posts: 2274
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SBASIC & C++

Post by NormanDunbar »

Regarding CPORT, I bought that years ago, and after running it on a couple of fairly simple programs, never used it again. The code output was pretty dire and I'm not sure it would be all that much more efficient.

Maybe I'll dig it out sometime, if my floppies still revolve that is, and have another play, but anything else I ever converted, such as my Archive Syntax Evaluator (or ArSE as i think Dilwyn called it!), was done by hand.

HTH.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
pjw
QL Wafer Drive
Posts: 1299
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: SBASIC & C++

Post by pjw »

Hi Norman,
If I remember my Turbo correctly, Def Integer means that those variables will be treated as integers and not floating point. Handy for pre SMS* QLs that can't do integer FOR loops, for example.
Thats what I thought at first, but I couldnt find it in the Turbo manual. I hoped it might have been a way to define long (32 bit) integers viz the code snippet from the relevant program below:

Code: Select all

..
100  DEF_INTEGER i,j
110  MANIFEST: n = 200000
120  crossed = ALCHP (n)
140  FOR i = 1 TO n
..
There is a QLib directive of the same name, but only for 16 bit integers, iirc. Compiled with QLib, this program would crash at i = 32k.

My conclusion in the end was that the DEF_INTEGER was a remnant left over from an earlier version of the program, which was originally compiled with QLib, using standard arrays. Later, more precision was wanted, so 15 bit integer indexing and standard arrays had to be abandoned. To compensate for loss of speed due to these changes, a switch was made to Turbo, thus MANIFEST:n = 200000.

Hows that for detective work ;)

Per


Per
dont be happy. worry
- ?
User avatar
vanpeebles
Commissario Pebbli
Posts: 2821
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: SBASIC & C++

Post by vanpeebles »

Elementary :lol:


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: SBASIC & C++

Post by EmmBee »

Hi Norman,

If the same program were to be written in Assembly Language, how much faster would you estimate this to be compared to C code?

Michael


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: SBASIC & C++

Post by dilwyn »

NormanDunbar wrote:Regarding CPORT, I bought that years ago, and after running it on a couple of fairly simple programs, never used it again. The code output was pretty dire and I'm not sure it would be all that much more efficient.
Maybe I'll dig it out sometime, if my floppies still revolve that is, and have another play, but anything else I ever converted, such as my Archive Syntax Evaluator (or ArSE as i think Dilwyn called it!), was done by hand.

Norm.
Excuse me! That name and the abbreviation were not down to DJC, but to a certain Mr N Dunbar not a million miles away from this page... :roll: (before I wrongly get the blame!)


Post Reply