In the CASim simulation environment, cellular automata are described in the specialized languages CDL, cellang, or caxl. These descriptions are then translated into Java or C code, which in turn is translated into machine code (Java: Just In Time compiler in the Java execution environment, C: compiler) and executed. But the same CDL code can be translated into many different Java or C codes, which are all functionally equivalent but can differ in speed by several orders of magnitude. This chapter describes different coding styles and measures their efficiencies. Only the speed of the evolution of a CA for many times steps is used as a criterion, since initialization is done only once, and the speed of display depends very much on the operating system, and should be considered separately.
The first section describes the simple translation of CDL to Java. Here we consider a number of coding options, which are considered good practice in object-oriented programming, but carry severe performance penalties. The second section describes the possibility of using a look-up table for the state transition rule. In the third section, this table is translated into a set of logical functions. This in itself does not lead to a performance improvement, but if it is combined with a packed coding, where the bits needed to store many cells are packed into one integer, this option can lead to a dramatic time saving. Finally, the fourth section describes how performance can be improved by translation into C and native code, eliminating the overhead of current Java programming environments for the state transition function, while retaining their portability and flexibility for the remaining portions of the code.