Sunday, August 14, 2005

BASIC concepts

Some of the first programs i ever wrote were in the computer language BASIC. Certainly among the first programs that i wrote that i still have were in that language. So, i downloaded a BASIC interpreter for my Linux machine. My Linux distribution didn't come with one. One of the things that i did first was write a little empty loop, and timed it:

10 print time$
20 for i = 1 to 1000
30 next i
40 print time$

Line 10 print the current time of day. Lines 20 and 30 are the empty loop. Line 40 prints the time of day again. The idea is to subtract one time from the other, and divide by the loop count. However, this loop doesn't take time, so i tried again with 1000000. This also doesn't take time, which is was a surprise. So, i tried 1000000000. This took 33 seconds. That means that this version of BASIC on my 2 year old low end PC (an Athlon 1800+, overclocked a little) can execute 30 million empty loops per second. Yet, i remembered numbers like 300 loops per second.

At first, i thought, wow, this is a really fast version of BASIC. So i ran a benchmark that i have in several languages, including C. It turns out that this BASIC is about 380 times slower than C. That's about what slower BASICS were. So where does the speed come from? Well, it's been about 20 years since i last ran it. That was on a PC/xt, which was an IBM PC clone with an 8088 running at 4.77 MHz. My newer machine is about 12,500 times faster in BASIC. Comparing the best runs in C, the new machine is 36,000 times faster. It might be noted that this is a floating point intensive benchmark, and the PC/xt had an 8087 floating point accelerator. Modern chips have this built in.

Anyway, i ported one of my first big programs, a 136 line blackjack game. As I recall, it nearly consumed the entire memory of the 1975 vintage Southwest Technical Products 6800. It had 12 KB of RAM. BASIC consumed about 8 KB. The text of the BASIC program was about 3 KB, leaving 5 KB for variables and overhead. Not surprisingly, when it runs on my faster machine, there are no noticeable delays. Oh yes. An hour on the PC/xt is now a tenth of a second - which is about as small a time as the eye can catch.

As a point of fact, i like running really old software. If it ran at all on the old hardware, then it should run like lightning on new hardware.

Software comes in two classes. Bleeding Edge and Obsolete. Bleeding Edge is the new stuff that doesn't really work yet. Obsolete is the old stuff that works. If its old enough, then it also works fast.

No comments: