Which programming languages ​​should be avoided

Avoid unnecessary memory access

The way in which functions are called up in the program code can change the energy consumption of software. Regardless of whether Rust, C ++ or Visual Basic for Applications, in many programming languages ​​variables can either be passed directly as a value to a function or as a reference to the storage location where the corresponding value can be found. Since value changes in the first case are restricted to the subroutine of the function, programmers do not need to worry about the wider effects of such changes. In contrast to the referential method, however, the direct value transfer requires an additional copy process for the relevant variables. The more often a function is called, the more values ​​are copied.

In general, avoiding unnecessary data movements and memory access is one of the basic recommendations for energy-optimized software development. A general approach for this is, for example, to bundle data requests into joint batch operations. The buffering of frequently required data segments in a cache also helps to minimize energy-intensive data transfers between processors and remote storage media. On the other hand, a cache needs additional power: If it is too large, this additional consumption may outweigh the energy efficiency gain due to the avoided data transfers. There is no simple rule of thumb for this. Instead, it always depends on an optimal relationship between cache size and the amount of data movements avoided.

Loop overhead slows down energy efficiency

Even following comparatively simple rules when setting up program loops can lead to considerable energy savings: Instead of floating-point numbers, for example, the data type integer should preferably be selected for counter variables - i.e. an unsigned integer. Ideally, there is also a zero as the termination condition. Because with a countdown, loops address fewer registers and therefore consume less power. In any case, many program loops often only consist of a few lines of code, such as increasing a counter, checking exit conditions and the execution code for the intended action. A not inconsiderable portion of the processing time is therefore spent on unproductive instructions that are used solely for loop control.

A remedy here is a technique called loop unrolling, with which a program loop can be unrolled or unrolled, as it were. The idea behind this is to explicitly write the loop body with the action code several times one after the other in order to execute the iteration steps individually and without the overhead for loop control. In a loop whose counter counts down from 3 to 0, for example, the same action code would appear four times in a row.

With manual loop unrolling, however, the higher energy efficiency of the processing results in a significantly larger source code, with the number of additional action code lines being multiplied by the number of loop runs. Such considerations become obsolete with all those compilers that automatically use different loop unrolling methods for code optimization.

Energy efficiency ranking: programming languages ​​in comparison

What language can be used to write the most economical programs? Is a machine-level compiled program per se more energy-efficient than software that requires a runtime environment such as the Java Runtime Environment or the .NET Framework? To answer this question, a Portuguese research team at Minho University Braga took a closer look at 27 programming languages. For reasons of comparability, only the latest generation of compilers, interpreters and runtime libraries were used. As benchmark criteria, the researchers compared the three parameters processing time, memory requirements and energy consumption. They have also divided their rankings according to type and programming paradigm - that is, compiled, virtualized or interpreted as well as imperative, object-oriented or script-based. The tasks of the various language programs included the calculation of random DNA sequences, the generation of Mandelbrot bitmaps and a complex run through binary trees.

The study shows in particular that the energy efficiency properties of a language, as well as the processing speed, depend on the type and complexity of the task to be solved. And the results reveal something else: the fastest code is by no means always the most energy-efficient. The Fortran language, for example, comes second in terms of power consumption. In terms of processing speed, however, it only achieved sixth position. In almost all areas of activity, C, C ++ and Rust are among the top 5 most energy-efficient languages. As expected, scripting languages ​​like Perl and Lua performed worst in the energetic language ranking.

language Energy (joules) Time (ms) Memory usage (MByte)
C. 39,8 1125 131
C ++ 41,23 1129 132
Rust 49,07 1263 180
Fortran 69,82 2112 133
Ada 95,02 2822 197

In the comparison task of the binary tree calculation, for example, the energy values ​​of C and Perl are 89 times apart.

Read comments (99) Go to the homepage