Tuesday, May 5, 2009

The performance myth

After a few years of developing in Java then in Matlab, I am now back maintaining code written in ANSI C. Mind you, the code is masterfully architected and written, you could not write it better in Smalltalk. This is industrial strength code that is expected to be very robust and highly performant.

Programmers often state you can write much faster code in C than in Java. As I implement my changes and additions, I find myself having to write ancillary code taking care of variable initialization, bounds checking, and object finalization. Also, I get bitten by side-effects while running regression tests.

Once I have added that ancillary code, a C program is no longer faster than a Java program. In fact in Java those functionalities are taken care of through very tightly written code in the run time system. It runs more efficiently than the code I can write while keeping the product price still within target and meeting shipping deadlines.

The dirty secret is that in C you can write lousy code that skips steps like variable initialization, bounds checking, and object finalization. This way you get faster code, but you leave open doors for malicious hackers. Also, debugging and maintenance of such code is much more expensive.

Speaking of code expense, although programmers are cheap, my time spent writing and debugging that ancillary code is also a cost.

In summary, you can write equally efficient commercial programs in Fortran, C, C++, C#, Smalltalk, Java, and others. If you are a good architect and frugal programmer, the programs will be surprisingly similar in style and performance. However, the more modern a language is, the less time it will take you to get there, and the less ugly code written by others you will encounter.

Vintage cars can be sexy, but I prefer the comfort of airbags, antilock brakes, traction control, and electronic fuel injection.

Operator programming a PDP-6 using papertape

1964: Tops 10 is developed as the major user software interface for Digital's 36-bit machines. Tops 10 was developed from a 6-K word monitor for the PDP-6. It included user files and I/O device independence, and a command control program.