A while back I was thinking about the two C compilers available for the QL. The Small C compiler is easy to use, quick to compile, but limited in it’s scope of the C language. The Lattice C compiler is not so easy to use, slow to compiler, but supports the full C language. The question is which one to use. Personally, I prefer the Small C compiler. When ever possible I will use it in my projects.
After comparing how much time each compiler takes to compile, I decided to find out which one produced faster code. With the Lattice C longer compile time, I expected it to spend some of that compile time optimising its code.
I used two simple benchmark programs. One for number crunching (prime numbers) and the other for recursion (fibonacci sequence). The prime number benchmark comes from an the CATS newsletter (Jan. 1990), by Duane Parker. Herb Schaaf wrote the C version for both compilers. The second program is from Dr. Dobb’s Journal (see code for issue).
Below is the results of these tests:
| Prime Numbers | Small C | Lattice C |
|---|---|---|
| 29000-32767 | 5 sec | 3 sec |
| 1000-32767 | 32 sec | 20 sec |
| Recursion | ||
| 189 sec | 193 sec |
After I ran the first benchmark, I expected Lattice C to out perform Small C on all benchmarks. I was surprised to see the second results.
It looks like Lattice C is faster for number crunching, but for recursive procedure calls, Small C is just a bit faster. The next time you are writing a C program consider which compiler might be better suited for your needs. With recursive programs, you won’t loose speed with Small C.
/* The Fibonacci benchmark tests
recursive procedure calls.
From Dr. Dobb's Journal
Feb. '89 P. 40
Small C Version
*/
#include <stdio_h>
#define NUMBER 24
#define NTIMES 34
main() {
int i, value, secs, d1[2], d2[2];
*d1 = date();
printf("%d iterations: ", NTIMES);
for (i=1; i <= NTIMES; i++)
value = fib(NUMBER);
printf("\n");
*d2 = date();
secs = d2[1] - d1[1];
printf("%d seconds\n",secs);
}
fib(x)
int x;
{
if ( x > 2 )
return (fib(x-1) + fib(x-2));
else
return (1);
}
/* The Fibonacci benchmark tests
recursive procedure calls.
From Dr. Dobb's Journal
Feb. '89 P. 40
Lattice C Version
*/
#include <flp1_stdio_h>
#include <flp1_qdos_h>
#define NUMBER 24
#define NTIMES 34
main() {
int i, value, secs, d1, d2;
d1 = readclock();
printf("%d iterations: ", NTIMES);
for (i=1; i <= NTIMES; i++)
value = fib(NUMBER);
printf("\n");
d2 = readclock();
secs = d2 - d1;
printf("%d seconds\n",secs);
}
fib(x)
int x;
{
if ( x > 2 )
return (fib(x-1) + fib(x-2));
else
return (1);
}
readclock(time)
int time;
{
struct REGS in, out;
in.D0 = 19;
QDOS1(&in,&out);
time = out.D1;
return(time);
}
Products
Downloadable Media
Image Gallery
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.