Energy Efficiency across Programming LanguagesHow Does Energy, Time, and Memory Relate?Rui PereiraMarco CoutoFrancisco Ribeiro, Rui RuaHASLab/INESC TECUniversidade do Minho, Portugalruipereira@di.uminho.ptHASLab/INESC TECUniversidade do Minho, Portugalmarco.email@example.comHASLab/INESC TECUniversidade do Minho, ome CunhaJoão Paulo FernandesJoão SaraivaNOVA LINCS, DI, FCTUniv. Nova de Lisboa, Portugaljacome@fct.unl.ptRelease/LISP, CISUCUniversidade de Coimbra, Portugaljpf@dei.uc.ptHASLab/INESC TECUniversidade do Minho, Portugalsaraiva@di.uminho.ptAbstractThis paper presents a study of the runtime, memory usageand energy consumption of twenty seven well-known software languages. We monitor the performance of such languages using ten different programming problems, expressedin each of the languages. Our results show interesting findings, such as, slower/faster languages consuming less/moreenergy, and how memory usage influences energy consumption. We show how to use our results to provide softwareengineers support to decide which language to use whenenergy efficiency is a concern.CCS Concepts Software and its engineering Software performance; General programming languages;Keywords Energy Efficiency, Programming Languages, Language Benchmarking, Green SoftwareACM Reference format:Rui Pereira, Marco Couto, Francisco Ribeiro, Rui Rua, Jácome Cunha,João Paulo Fernandes, and João Saraiva. 2017. Energy Efficiencyacross Programming Languages. In Proceedings of SLE’17, Vancouver,BC, Canada, October 23–24, 2017, 12 oductionSoftware language engineering provides powerful techniquesand tools to design, implement and evolve software languages. Such techniques aim at improving programmersPermission to make digital or hard copies of all or part of this work forpersonal or classroom use is granted without fee provided that copies are notmade or distributed for profit or commercial advantage and that copies bearthis notice and the full citation on the first page. Copyrights for componentsof this work owned by others than ACM must be honored. Abstracting withcredit is permitted. To copy otherwise, or republish, to post on servers or toredistribute to lists, requires prior specific permission and/or a fee. Requestpermissions from firstname.lastname@example.org.SLE’17, October 23–24, 2017, Vancouver, BC, Canada 2017 Association for Computing Machinery.ACM ISBN 978-1-4503-5525-4/17/10. . . tivity - by incorporating advanced features in the language design, like for instance powerful modular and typesystems - and at efficiently execute such software - by developing, for example, aggressive compiler optimizations.Indeed, most techniques were developed with the main goalof helping software developers in producing faster programs.In fact, in the last century performance in software languageswas in almost all cases synonymous of fast execution time(embedded systems were probably the single exception).In this century, this reality is quickly changing and software energy consumption is becoming a key concern forcomputer manufacturers, software language engineers, programmers, and even regular computer users. Nowadays, itis usual to see mobile phone users (which are powerful computers) avoiding using CPU intensive applications just tosave battery/energy. While the concern on the computers’energy efficiency started by the hardware manufacturers, itquickly became a concern for software developers too .In fact, this is a recent and intensive area of research whereseveral techniques to analyze and optimize the energy consumption of software systems are being developed. Suchtechniques already provide knowledge on the energy efficiency of data structures [14, 26] and android language ,the energy impact of different programming practices both inmobile [17, 21, 30] and desktop applications [25, 31], the energy efficiency of applications within the same scope [2, 16],or even on how to predict energy consumption in severalsoftware systems [4, 13], among several other works.An interesting question that frequently arises in the software energy efficiency area is whether a faster program isalso an energy efficient program, or not. If the answer is yes,then optimizing a program for speed also means optimizingit for energy, and this is exactly what the compiler construction community has been hardly doing since the verybeginning of software languages. However, energy consumption does not depends only on execution time, as shownin the equation Ener дy Time Power . In fact, there areseveral research works showing different results regardingthis subject [1, 20, 26, 28, 34, 37]. A similar question arises
SLE’17, October 23–24, 2017, Vancouver, BC, Canadawhen comparing software languages: is a faster language, agreener one? Comparing software languages, however, is anextremely complex task, since the performance of a languageis influenced by the quality of its compiler, virtual machine,garbage collector, available libraries, etc. Indeed, a softwareprogram may become faster by improving its source code,but also by "just" optimizing its libraries and/or its compiler.In this paper we analyze the performance of twenty sevensoftware languages. We consider ten different programmingproblems that are expressed in each of the languages, following exactly the same algorithm, as defined in the ComputerLanguage Benchmark Game (CLBG) . We compile/execute such programs using the state-of-the-art compilers,virtual machines, interpreters, and libraries for each of the27 languages. Afterwards, we analyze the performance ofthe different implementation considering three variables:execution time, memory consumption and energy consumption. Moreover, we analyze those results according to thelanguages’ execution type (compiled, virtual machine andinterpreted), and programming paradigm (imperative, functional, object oriented, scripting) used. For each of the execution types and programming paradigms, we compiled asoftware language ranking according to each variable considered. Our results show interesting findings, such as, slower/faster software languages consuming less/more energy, andhow memory usage influences energy consumption. Moreover, we discuss how to use such results to provide softwareengineers support to decide which language to use whenenergy efficiency is a concern.This work builds on previous work  where it was presented a framework to allow the monitoring of the energyconsumption of executable software programs. In that work,the C-based framework was used to define a preliminaryranking of ten languages (where only energy was considered). We reuse the energy monitoring framework (brieflydescribed in Section 2.2) to analyze the energy efficiencyof 27 languages and (almost) 270 programs. We have alsoextended it in order to monitor memory consumption, aswell.This paper is organized as follows: Section 2 exposes thedetailed steps of our methodology to measure and compareenergy efficiency in software languages, followed by a presentation of the results. Section 3 contains the analysis anddiscussion on the obtained results, where we first analyzewhether execution time performance implies energy efficiency, then we examine the relation between peak memory usage and memory energy consumption, and finally wepresent a discussion on how energy, time and memory relate in the 27 software languages. In Section 4 we discussthe threats to the validity of our study. Section 5 presentsthe related work, and finally, in Section 6 we present theconclusions of our work.R. Pereira et. al.2Measuring Energy in SoftwareLanguagesThe initial motivation and primary focus of this work is tounderstand the energy efficiency across various programming languages. This might seem like a simple task, but itis not as trivial as it sounds. To properly compare the energy efficiency between programming languages, we mustobtain various comparable implementations with a goodrepresentation of different problems/solutions.With this in mind, we begin by trying to answer the following research question: RQ1: Can we compare the energy efficiency of softwarelanguages? This will allow us to have results in whichwe can in fact compare the energy efficiency of popular programming languages. In having these results,we can also explore the relations between energy consumption, execution time, and memory usage.The following subsections will detail the methodologyused to answer this question, and the results we obtained.2.1The Computer Language Benchmarks GameIn order to obtain a comparable, representative and extensiveset of programs written in many of the most popular andmost widely used programming languages we have exploredThe Computer Language Benchmarks Game . (CLBG).The CLBG initiative includes a framework for running,testing and comparing implemented coherent solutions fora set of well-known, diverse programming problems. Theoverall motivation is to be able to compare solutions, withinand between, different programming languages. While theperspectives for comparing solutions have originally essentially analyzed runtime performance, the fact is that CLBGhas recently also been used in order to study the energyefficiency of software [6, 20, 24].In its current development stage, the CLBG has gatheredsolutions for 13 benchmark problems, such that solutionsto each such problem must respect a given algorithm andspecific implementation guidelines. Solutions to each problem are expressed in, at most, 28 different programminglanguages.The complete list of benchmark problems in the CLBGcovers different computing problems, as described in Table 1.Additionally, the complete list of programming languages inthe CLBG is shown in Table 2, sorted by their paradigms.2.2Design and ExecutionOur case study to analyze the energy efficiency of softwarelanguages is based on the CLBG.
SLE’17, October 23–24, 2017, Vancouver, BC, CanadaIn order to ensure that the overhead from our measuring framework, using the system function, is negligible ornon-existing when compared to actually measuring withRAPL inside a program’s source code, we design a simpleexperiment. It consisted of measuring the energy consumption inside of both a C and Java language solution, usingRAPL and jRAPL respectively, and comparing the results tothe measurements from our C language energy measuringframework. We found the resulting differences to be insignificant, and therefore negligible, thus we conclude that wecould use this framework without having to worry aboutimprecisions in the energy measurements.Also, we chose to measure the energy consumption andthe execution time of a solution together, since the overheadwill be the same for every measurement, and so this shouldnot affect the obtained values.The memory usage of a solution was gathered using thetime tool, available in Unix-based systems. This tool runs aprogram given as an argument, and summarizes the systemresources used by that program, which includes the peak ofmemory usage.Each benchmark solution was executed and measured 10times, in order to obtain 10 energy consumption and execution time samples. We did so to reduce the impact of coldstarts and cache effects, and to be able to analyze the measurements’ consistency and avoid outliers. We followed thesame approach when gathering results for memory usage.For some benchmark problems, we could not obtain anyresults for certain programming languages. In some cases,there was no source code available for the benchmark problem (i.e., no implementation was provided in a concrete language which reflects a language coverage below 100%).2In other cases, the code was indeed provided but either thecode itself was already buggy or failing to compile or execute,as documented in CLBG, or, in spite of our best efforts, wecould not execute it, e.g., due to missing libraries.3 Fromnow on, for each benchmark problem, we will refer as itsexecution coverage to the percentage of (best) solutions forit that we were actually able to successfully execute.All studies were conducted on a desktop with the following specifications: Linux Ubuntu Server 16.10 operatingsystem, kernel version 4.8.0-22-generic, with 16GB of RAM,a Haswell Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz.2.3ResultsThe results from our study are partially shown in this section,with the remainder shown in the online appendix for thispaper 1 . Table 3, and the left most tables under Results - A.Data Tables in the appendix, contains the measured data fromdifferent benchmark solutions. We only show the results2 Inthese cases, we will include an n.a. indication when presenting theirresults.3 In these cases, we will include an n.e. indication when presenting theirresults.R. Pereira et. al.for binary-trees, fannkuch-redux, and fasta within thepaper, which are the first 3 ordered alphabetically. Each rowin a table represents one of the 27 programming languageswhich were measured.The 4 rightmost columns, from left to right, represent theaverage values for the Energy consumed (Joules), Time ofexecution (milliseconds), Ratio between Energy and Time,and the amount of peak memory usage in Mb. The Energyvalue is the sum of CPU and DRAM energy consumption.Additionally, the Ratio can also be seen as the average Power,expressed in Kilowatts (kW). The rows are ordered accordingto the programming language’s energy consumption, fromlowest to highest. Finally, the right most tables under Results- A. Data Tables contain the standard deviation and averagevalues for our measured CPU, DRAM, and Time, allowingus to understand the variance.The first column states the name of the programming languages, preceded by either a (c), (i), or (v) classifying them aseither a compiled, interpreted, or virtual-machine language,respectively. In some cases, the programming language namewill be followed with a x / y and/or x / y symbol. The firstset of arrows indicates that the language would go up byx positions ( x ) or down by y positions ( y ) if ordered byexecution time. For example in Table 3, for the fasta benchmark, Fortran is the second most energy efficient language,but falls off 6 positions down if ordered by execution time.The second set of arrows states that the language would goup by x positions ( x ) or down by y positions ( y ) if orderedaccording to their peak memory usage. Looking at the sameexample benchmark, Rust, while the most energy efficient,would drop 9 positions if ordered by peak memory usage.Table 4 shows the global results (on average) for Energy,Time, and Mb normalized to the most efficient language inthat category. Since the pidigits benchmark solutions onlycontained less than half of the languages covered, we did notconsider this one for the global results. The base values areas follows: Energy for C is 57.86J, Time for C is 2019.26ms, andMb for Pascal is 65.96Mb. For instance, Lisp, on average,consumes 2.27x more energy (131.34J) than C, while taking2.44x more time to execute (4926.99ms), and 1.92x morememory (126.64Mb) needed when compared to Pascal.To better visualize and interpret the data, we also generated two different sets of graphical data for each of thebenchmarks. The first set, Figures 1-3 and the left most figures under Results - C. Energy and Time Graphs in the appendix, contains the results of each language for a benchmark,consisting of three joint parts: a bar chart, a line chart, and ascatter plot. The bars represent the energy consumed by thelanguages, with the CPU energy consumption on the bottomhalf in blue dotted bars and DRAM energy consumption onthe top half in orange solid bars, and the left y-axis representing the average Joules. The execution time is representedby the line chart, with the right y-axis representing averagetime in milliseconds. The joining of these two charts allow
Energy Efficiency across Programming Languagesus to better understand the relationship between energy andtime. Finally, a scatter plot on top of both represents the ratio between energy consumed and execution time. The ratioplot allows us to understand if the relationship between energy and time is consistent across languages. A variation inthese values indicates that energy consumed is not directlyproportional to time, but dependent on the language and/orbenchmark solution.The second set, Figures 4-6 and the right most figuresunder Results - C. Energy and Time Graphs in the appendix,consists of two parts: a bar chart, and a line chart. The bluebars represent the DRAM’s energy consumption for each ofthe languages, with the left y-axis representing the averageJoules. The orange line chart represents the peak memoryusage for each language, with the right y-axis representingthe average Mb. The joining of these two allows us to lookat the relation between DRAM energy consumption and thepeak memory usage for each language in each benchmark.By turning to the CLBG, we were able to use a large setof software programming languages which solve variousdifferent programming problems with similar solutions. Thisallowed us to obtain a comparable, representative, and extensive set of programs, written in several of the most popularlanguages, along with the compilation/execution options,and compiler versions. With these joined together with ourenergy measurement framework, which uses the accurate Intel RAPL tool, we were able to measure, analyze, and comparethe energy consumption, and in turn the energy efficiency,of software languages, thus answering RQ1 as shown withour results. Additionally, we were also able to measure theexecution time and peak memory usage which allowed usto analyze how these two relate with energy consumption.The analysis and discussion of our results is shown in thenext section.3Analysis and DiscussionIn this section we will present an analysis and discussion onthe results of our study. While our main focus is on understanding the energy efficiency in languages, we will also tryto understand how energy, time, and memory relate. Additionally, in this section we will try to answer the followingthree research questions, each with their own designatedsubsection. RQ2: Is the faster language always the most energyefficient? Properly understanding this will not onlyaddress if energy efficiency is purely a performanceproblem, but also allow developers to have a greaterunderstanding of how energy and time relates in alanguage, and between languages. RQ3: How does memory usage relate to energy consumption? Insight on how memory usage affects energy consumption will allow developers to better understandhow to manage memory if their concern is energyconsumption.SLE’17, October 23–24, 2017, Vancouver, BC, Canada RQ4: Can we automatically decide what is the best programming language considering energy, time, and memory usage? Often times developers are concerned withmore than one (possibly limited) resource. For example, both energy and time, time and memory space,energy and memory space or all three. Analyzing thesetrade-offs will allow developers to know which programming languages are best in a given scenarios.3.1Is faster, greener?A very common misconception when analyzing energy consumption in software is that it will behave in the sameway execution time does. In other words, reducing the execution time of a program would bring about the sameamount of energy reduction. In fact, the Energy equation,Energy (J) Power (W) x Time(s), indicates that reducing time implies a reduction in the energy consumed.However, the Power variable of the equation, which cannot be assumed as a constant, also has an impact on theenergy. Therefore, conclusions regarding this issue divergesometimes, where some works do support that energy andtime are directly related , and the opposite was also observed [20, 28, 34].The data presented in the aforementioned tables and figures lets us draw an interesting set of observations regardingthe efficiency of software languages when considering bothenergy consumption and execution time. Much like  and, we observed different behaviors for energy consumption and execution time in different languages and tests.By observing the data in Table 4, we can see that the Clanguage is, overall, the fastest and most energy efficient.Nevertheless, in some specific benchmarks there are moreefficient solutions (for example, in the fasta benchmark itis the third most energy efficient and second fastest).Execution time behaves differently when compared to energy efficiency. The results for the 3 benchmarks presentedin Table 3 (and the remainder shown in the appendix) showseveral scenarios where a certain language energy consumption rank differs from the execution time rank (as the arrowsin the first column indicate). In the fasta benchmark, forexample, the Fortran language is second most energy efficient, while dropping 6 positions when it comes to executiontime. Moreover, by observing the Ratio values in Figures 1to 3 (and the remainder in the appendix under Results - C. Energy and Time Graphs), we clearly see a substantial variationbetween languages. This means that the average power isnot constant, which further strengthens the previous point.With this variation, we can have languages with very similarenergy consumptions and completely different executiontimes, as is the case of languages Pascal and Chapel in thebinary trees benchmark, which energy consumption differ roughly by 10% in favor of Pascal, while Chapel takesabout 55% less time to execute.
Energy Efficiency across Programming LanguagesSLE’17, October 23–24, 2017, Vancouver, BC, CanadaFigure 4. Energy and memory graphical data for binary-treesFigure 5. Energy and memory graphical data for fannkuch-reduxFigure 6. Energy and memory graphical data for fastaCompiled languages tend to be, as expected, the fastestand most energy efficient ones. On average, compiled languages consumed 120J to execute the solutions, while forvirtual machine and interpreted languages this value was576J and 2365J, respectively. This tendency can also be observed for execution time, since compiled languages took5103ms, virtual machine languages took 20623ms, and interpreted languages took 87614ms (on average). Grouped bythe different paradigms, the imperative languages consumedand took on average 125J and 5585ms, the object-orientedconsumed 879J and spent 32965ms, the functional consumed1367J
virtual machines, interpreters, and libraries for each of the 27 languages. Afterwards, we analyze the performance of the different implementation considering three variables: execution time, memory consumption and energy consump-tion. Moreover, we analyze those results according to the languages' execution type (compiled, virtual machine and