Compilers, languages, options, and astronomical images.
This paper describes some experiments comparing different languages, compilers, and compiler options to see how well they handle access to individual elements of a 2D rectangular floating point array. Such arrays are common in astronomical data, and handling them efficiently is important, particularly given the range of execution times demonstrated in this paper for different ways of coding the same simple problem. This problem was coded in a number of languages, among them C/C++, Fortran, Julia, Python, R, Javascript, and Assembler. Some of the conclusions of this fairly simple experiment are what might be expected - modern compilers are very impressive, and can effortlessly match hand-coded assembler, but compiler options matter, particularly when using template libraries, and the convenience of interpreted languages comes at a high cost. However the range of execution times (and hence the gain from doing things in an efficient way) was even greater than had originally been expected. The fastest code tested here was around 1,000,000 - one million - times faster than the slowest code tested. (Admittedly, that particular slow code was something of an extreme outlier, but it had genuinely been expected that it would improve execution times; it simply hit a quirk of the language involved.) Even without that extreme case, the range of execution times covered four orders of magnitude. Understanding the underlying capabilities of the processor, for example its support for vector instructions, can sometimes lead to a selection of compiler options that pay dividends in execution time.