<html><head><title>BASIC compressors compared - BasCrunch, BasCompress, BasShrink and StrongBS</title></head><!--(c) G.C. '98 A.R.R.-->
<body background="../../images/tile">
<center><h3>BASIC compressors compared - BasCrunch, BasCompress, BasShrink and StrongBS</h3></center>
<p>
 On our machine, we are gifted with a very good version of BASIC, for free, with the operating system: it's fairly fast (especially for those with StrongARMs), provides good features for structured programming (it's not every BASIC interpreter which supports <tt>CASE</tt> structures, or even <tt>PROC</tt>edures) and is particularly well adapted for writing low-level code, with a BASIC-like interface to modules, in the <tt>SYS</tt> command, and the BASIC assembler, for producing hybrid BASIC/ARM programs.
<p>
 On the other hand, BASIC just isn't as fast as C or, by a much greater degree, assembler; there are several BASIC compilers available for RISC OS, including ABC and RiscBASIC, but these are generally over fifty pounds, which is certainly a good investment if you're serious about producing BASIC software, especially for commercial channels (Rhapsody 2 is compiled BASIC), but might not be such a viable option if you're just producing a quickie for your own purposes or some freeware software. Another solution, which has been known to provide <i>large</i> speed increases, is through the use of a BASIC compressor. This works by changing variable and routine names to the minimum number of letters possible, removing comments and concatenating lines. The result is smaller, barely readable and, perhaps most importantly of all, faster code.
<p>
 There are a whole variety of these pieces of software on the platform, both freeware and shareware. I've not, as yet, seen a commercial offering, but I doubt that there's really a serious market for this. I've been collecting these for a few years now and I thought it might be useful if I began to choose a leader.
<p>
<h4>The Candidates:</h4>
<p>
 The shareware offerings are BasCompress, by Cy Booker, and BasShrink, by John 'Lofty' Wallace. Both of my test versions are the non-registered editions, which, in some cases, means I don't have all the features of the registered version, although I've tried to compensate; additionally, both of these versions are several years old.
<p>
 BasCompress' registration is a 10, but an extra 5 gets you a complete printed manual, which is always a very good incentive. Version 1 of BasShrink, which <i>is</i> in the public domain, has evolved (by now) into BasShrink version 3, at a cost of 5.
<p>
 The freeware offerings are BasCrunch, by Mike Harrison, and StrongBS, by Mohsen Alshayef. BasCrunch, too, is an old version, but, by comparison, my version of StrongBS is from 1997.
<p>
<h4>The Capabilities:</h4>
<p>
 BasCrunch has been my mainstay, now, for several years; I've software dating back three years with squashed versions provided. Although the only wimp element of the software was an icon bar presence and save box, added by Stuart Hickinbottom, the non-desktop nature of it won't be of any particular detriment. It is reasonably well featured, including safely-implemented line concatenation, production of immediate constants in the shortest number of characters (by converting base) and highly-optimised reduction of variable names (all of them will come out in under three characters and the letters of the names have been designed with speed in the BASIC interpreter in mind). The software is, however, not configurable.
<p>
 BasCompress provides a window with places to drag BASIC files to and drag them from, either before or after compression, with compressed files being saved whenever a filename becomes available. BasCompress provides all the features of BasCrunch, but it will also remove unused routines, convert software interrupt names to numbers (which is a significant time saver) and checks the syntax of the input code for properly-closed structures, matched parentheses and multiple definitions of procedures, in case your debugging code is still the version in place when you compress the code! Particular variables can be set to be left unconverted, for use in <tt>EVAL</tt> instructions.
<p>
 It's also very configurable, with options to allow BasCompress to deal with different styles of code (for example, if you always write routines with one exit, setting <i>Report multiple exits from a routine</i> is a very useful debugging switch) and configure how detailed the log and cross-referencing data is. It can be invoked from the command line, so that you can have an obey file prepared to compress the software when needed. BasCompress also provides the facility to cross-reference variable and procedure names in the code, in addition to the compressed output. A feature currently missing from this review's other candidates is the ability to include <tt>LIBRARY</tt> files while compressing.
<p>
 The main reason I didn't use BasCompress as my main compressor was that it was occasionally unreliable in producing working output code from working input code.
<p>
 BasShrink also provides a desktop, windowed interface, as well as, again, a CLI option. However, it provides a display of the sizes of the source and output code. Configuration here is supplied by a series of tickable options in the main window and the current configuration can be saved. BasShrink can be configured to maintain the names of variables and functions that <i>begin</i> with a certain string, which is very useful for compressing a file, but still allowing it to use a library, providing that all your library function and procedure names start with the same text. It also provides the facility to remove not only comments introduced with <tt>REM</tt>, but also with <tt>*|</tt>; an interpretation time saver includes the ability to convert all <tt>ASC(chr)</tt> commands using constants to the actual ASCII character.
<p>
 StrongBS is probably the most fully-featured compressor of them all. Apart from the usual functions, it claims to provide many, many never-before seen features, including evaluating constant mathematical expressions to their actual value, optimisation of parentheses in operations and of use of indirection operators, concatenation of multi-line <tt>IF</tt> structures,  <tt>DATA</tt> lines, <tt>READ</tt>s, <tt>DIM</tt>s, <tt>LOCAL</tt>s, assembler directives and <tt>VDU</tt> statements, killing null variables and, perhaps most advanced of all, a (currently developing) facility to pre-assemble inline ARM assembler code within the text of the tokenised BASIC file.
<p>
 A very nice desktop front end is provided, with multi-tasking conversion and a progress monitor bar. The code is written in hand-crafted ARM assembler for <i>respectable speed</i>, which is a fairly major understatement. The only things I can think of that it doesn't do are auto-including of <tt>LIBRARY</tt> files, inlining of functions and procedures and unrolling of loops, the last two of which I've yet to see in <i>any</i> BASIC compressor; however, even this may change, because the software is totally modular and third parties have already started to provide extra functions, the range of which has probably increased since the copy I have. Another added bonus is that it also compresses many pre-compressed files, allowing you to search your hard drive for any BASIC software you need making faster and do so, although the few I tried all failed. As another excellent feature, StrongBS is outstandingly configurable: literally <i>everything</i> can be enabled, disabled or otherwise qualified and the facility is provided to save the current configuration out, as a new <i>squash mode</i>.
<p>
 So highly regarded is this compressor that people at Acorn have it and even Cy Booker, programmer of BasCompress, uses it!
<p>
<h4>The Compression:</h4>
<p>
 For the purposes of this review, I have collected BASIC programs from several sources to be processed:
<ul>
<li> A quick, simple 3D test program I wrote a while back, which displays a spinning object. This file included two libraries, from which I manually removed excess procedures: the tests of resultant code size after compression should be based on the same source and compressors which remove routines would, effectively, be making the source smaller.
<br>
<li> <tt>COMPUTE_PI</tt>, the function of which is reasonably obvious.
</ul>
<p>
<pre>
BASIC Source   BasCrunch    BasCompress  BasShrink    StrongBS
PlotObj        7            1.25         5            2.5
COMPUTE_PI     3            1.25         1.75         2.5
</pre>
<p>
 Also, I have listed the original file size as compared to the compressed file size:
<p>
<pre>
BASIC Source   BasCrunch    BasCompress  BasShrink    StrongBS
PlotObj        17%          15%          19%          15%
COMPUTE_PI     82%          76%          93%          73%
</pre>
<p>
 Being written in uncompressed BASIC, BasCrunch unsurprisingly does worst in terms of compress time. BasCompress beats StrongBS, although we should remember that StrongBS multitasks and so is bound to appear slower. However, StrongBS still scores highest in terms of compression, although BasCompress is, still, reasonably close.
<p>
<h4>The Code:</h4>
<p>
 The crucial factor in the quality of a compressor is the speed of the compressed code. Each of the above test subjects is again used, but is this time tested for a certain task at run-time:
<dl>
<dt><tt>PlotObj</tt><dd>The engine's speed, in frames per second
<dt><tt>COMPUTE_PI</tt><dd>A computation of PI to 500 digits
</dl>
<p>
 The table below gives the results of the test, in terms of speed. In some cases, certain compressors have failed to produce a working output. When this is the case, <tt>FAIL</tt> is recorded as the time taken.
<p>
<pre>
BASIC Source   Original     BasCrunch    BasCompress  BasShrink    StrongBS
PlotObj        12.5 fps     15.9 fps     FAIL         16 fps       20.2 fps
COMPUTE_PI     15.83 secs   14.46 secs   14.46 secs   14.46 secs   14.47 secs
</pre>
<p>
 The freeware version of BasShrink has line concatenation disabled, which detracts from the quality of the software. The BasShrink compressed code has been processed through StrongBS with just line concatenation enabled.
<p>
 The results indicate the best use of BASIC compressors: files, such as <tt>COMPUTE_PI</tt>, which makes use of single letter variable names already, does produce speed increases when compressed, but these increases are almost constant between the different compressors; however, the <tt>PlotObj</tt> code, which makes use of long variable names, benefits greatly from compression, with StrongBS clearly showing its ability to leave the rest of the pack behind.
<p>
<h4>The Conclusion:</h4>
<p>
 The choice is fairly obvious: unless you really need <tt>LIBRARY</tt> linking with your compression, StrongBS is the one to go for: it's easily configurable, fairly fast, multi-tasking and generally produces both the smallest and fastest code, due to its range of new features over other compressors. The fact that it's free is miraculous; it would be perfectly reasonable to make this shareware. As it is, it oozes professional design of interface and, being modular and written in assembler, code. It is simply the most proficient tool for the job.
<p>
Name: BasCrunch<br>
Authors: Mike Harrison, with Stuart Hickinbottom<br>
Status: Freeware<br>
<p>
Name: BasCompress<br>
Authors: Cy Booker<br>
Status: Shareware<br>
<p>
Name: BasShrink<br>
Authors: John Wallace<br>
Status: Freeware, but later commercial versions may be available<br>
<p>
Name: StrongBS<br>
Authors: Mohsen Alshayef, with David Sharp and, perhaps, others<br>
Status: Freeware<br>
<p>
Availability: At a wild guess, I'd try a PD library; all except BasCrunch can be obtained on <a href="../Commercial/PDCD5">PDCD5</a><br>
</body>
</html>