Page 5 of 11
Re: SBASIC & C++
Posted: Wed Dec 03, 2014 7:59 pm
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.
Re: SBASIC & C++
Posted: Wed Dec 03, 2014 9:19 pm
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
Re: SBASIC & C++
Posted: Wed Dec 03, 2014 10:18 pm
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.
Re: SBASIC & C++
Posted: Mon Dec 08, 2014 1:01 pm
by pjw
Tobias,
What is the DEF_INTEGER on line 100 for?
Per
Re: SBASIC & C++
Posted: Wed Dec 17, 2014 10:44 pm
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.
Re: SBASIC & C++
Posted: Wed Dec 17, 2014 10:51 pm
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.
Re: SBASIC & C++
Posted: Thu Dec 18, 2014 2:46 am
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
Re: SBASIC & C++
Posted: Thu Dec 18, 2014 8:10 am
by vanpeebles
Elementary

Re: SBASIC & C++
Posted: Thu Dec 18, 2014 8:33 am
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
Re: SBASIC & C++
Posted: Thu Dec 18, 2014 2:16 pm
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...

(before I wrongly get the blame!)