Analyzing Programming Languages' Energy Consumption: an Empirical Study
Total Page:16
File Type:pdf, Size:1020Kb
Analyzing Programming Languages’ Energy Consumption: An Empirical Study Stefanos Georgiou Maria Kechagia Diomidis Spinellis Athens University of Economics and Delft University of Technology Athens University of Economics and Business Delft, The Netherlands Business Athens, Greece [email protected] Athens, Greece [email protected] [email protected] ABSTRACT increase of energy consumption.1 Recent research conducted by Motivation: Shifting from traditional local servers towards cloud Gelenbe and Caseau [7] and Van Heddeghem et al. [14] indicates a computing and data centers—where different applications are facil- rising trend of the it sector energy requirements. It is expected to itated, implemented, and communicate in different programming reach 15% of the world’s total energy consumption by 2020. languages—implies new challenges in terms of energy usage. Most of the studies, for energy efficiency, have considered energy Goal: In this preliminary study, we aim to identify energy implica- consumption at hardware level. However, there is much of evidence tions of small, independent tasks developed in different program- that software can also alter energy dissipation significantly [2, 5, 6]. 2 3 ming languages; compiled, semi-compiled, and interpreted ones. Therefore, many conference tracks (e.g. greens, eEnergy) have Method: To achieve our purpose, we collected, refined, compared, recognized the energy–efficiency at the software level as an emerg- and analyzed a number of implemented tasks from Rosetta Code, ing research challenge regarding the implementation of modern that is a publicly available Repository for programming chrestomathy. systems. Results: Our analysis shows that among compiled programming Nowadays, more companies are shifting from traditional local languages such as C, C++, Java, and Go offers the highest energy servers and mainframes towards the data centers. Some of the efficiency for all of our tested tasks compared toC#, vb.net, and main characteristic of this approach is the pay-as-you-go feature, Rust. Regarding interpreted programming languages php, Ruby, elasticity, scalability upon heavy workloads, and the hosting of any and JavaScript exhibit the most energy savings compared to Swift, applications implemented in a variety of programming languages. R, Perl, and Python. However, there is a limited number of research works that examine the energy impact of programming tasks implemented in different CCS CONCEPTS programming languages. To identify trends and possible gains regarding the reduce of • Hardware → Power estimation and optimization; • Soft- energy consumption, during software development, we conducted ware and its engineering → Software libraries and repositories; an empirical study using data from the Rosetta Code Repository. Software design tradeoffs; Our goal is to elicitate energy usage from small tasks implemented in a variety of well-known and most used programming languages. KEYWORDS To this end, our results show which of the interpreted and compiled Energy Efficiency, Energy Optimization, Programming Languages programming languages offer more energy efficient implementa- tions for specific tasks. Moreover, we show the negative impact if ACM Reference format: choosing an inefficient implementation. Stefanos Georgiou, Maria Kechagia, and Diomidis Spinellis. 2017. Analyzing The remainder of this paper is organized as follows. Section 2 de- Programming Languages’ Energy Consumption: An Empirical Study. In Pro- ceedings of Panhellenic Conference on Informatics, Larrisa, Greece, September scribes: 1) our experimental setup, 2) our dataset’s cleaning method, 2017 (PCI ’17), 6 pages. 3) the software and hardware tools we used, and 4) our analysis https://doi.org/10.475/123_4 methodology. In Section 3, we present our preliminary results and in Section 4 we discuss potential threats to validity. In Section 5, we list prior work done in the field and compare it with ours. Finally, we conclude in Section 6 and we present future research directions. 1 INTRODUCTION The increasing demands on services and computational applications 2 EXPERIMENTAL SETUP from ict-related products are major factors that contribute to the In this Section, we describe our approach for conducting our ex- periment and for retrieving measurements. Initially, we provide Permission to make digital or hard copies of part or all of this work for personal or information about the obtained dataset and the way we selected classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation 1Although in the physical sense energy cannot be consumed, we will use the terms on the first page. Copyrights for third-party components of this work must be honored. energy “consumption”, “requirement”, and “usage” to refer to the conversion of elec- For all other uses, contact the owner/author(s). trical energy by ict equipment into thermal energy dissipation to the environment. PCI ’17, September 2017, Larrisa, Greece Correspondingly, we will use the term energy “savings", “reduction", “efficiency", and © 2017 Copyright held by the owner/author(s). “optimization" to refer to reduced consumption ACM ISBN 123-4567-24-567/08/06...$15.00 2http://greens.cs.vu.nl/ https://doi.org/10.475/123_4 3http://conferences.sigcomm.org/eenergy/2017/cfp.php PCI ’17, September 2017, Larrisa, Greece S. Georgiou et al. Table 1: Programming Languages, Compilers and Inter- selection. The selected tasks were: array-concatenation, classes (cre- preters ating an object and calling a method to print a variable’s value), url-encoding and decoding, bubble-, quick-, insertion-, merge-, and Programming Compilers and selection- sorting algorithms. Moreover, to further refine our dataset Languages Interpreters version we used the following steps: Compiled C, C++ gcc version 6.3.1 20161221- • Some of the tasks offered more than one implementation for Go go version go1.7.5 the same programming language. Thus, we had to browse Rust rustc version 1.18.0 manually through each directory and remove them until we had only one that is consistent with the other implemen- Semi- vb.net mono version 4.4.2.0 (vbnc) tation. For instance, when most of the implemented tasks Compiled C# mono version 4.4.2.0 (mics) used iterative implementation, we removed the ones using Java javac version 1.8.0_131 recursion. Interpreted JavaScript node version 6.10.3 • The Java file names and their public names where differ- Perl perl version 5.24.1 ent which resulted in compilation error. Thus, we had to php php version 7.0.19 manually change them. Python python version 2.7.13 • Some of the implementations did not have main classes, or R Rscript version 3.3.3 the same data with other tasks. Therefore, we changed the Ruby ruby version 2.3.3p222 source code to offer consistency. Swift swift version 3.0.2 • For some programming languages that do not offer the class option such as C and Go, we used structs. • Some of the tasks were relatively small and finished faster our tasks and refine it. Furthermore, we explain our experimental than a second which makes it impossible for our power setup, the hardware and software tools we used. analyzer to capture those results. Therefore, we added all the selected tasks in an iteration loop of a million times. 2.1 Dataset After applying the above modifications on our dataset, we cat- 4 In the context of this study, we used the Rosetta Code, which is a egorized our programming languages in three main categories, publicly available programming chrestomathy site that offers 851 namely, compiled, semi-compiled, and interpreted (see Table 1). For tasks, 230 draft tasks, and a collection of 658 different programming the programming languages which offer a semi-compiled approach languages. In general, not all tasks are implemented, and not all such as Java, vb.net, and C#, we added them under the category of tasks are possible to implement in all languages. For our study, compiled languages for our experiments. In addition, we compared 5 we cloned a Github Repository that contains all the currently the compiled and semi-compiled implementations while having implemented tasks introduced in the Rosetta Code website. scenarios with and without compiler optimizations. To select popular programming languages, we consulted the 6 website of tiobe, a software quality company. Tiobe uses a search 2.2 Hardware and Software components query for index rating of the most popular programming languages around the web on a monthly basis. This query is based on a for- 2.2.1 Hardware Components. The physical tools we used com- 9 mula7 that uses the highest ranked search engines (according to prise: 1) portable personal computer (HP EliteBook 840 G3), 2) 10 Alexa)8 and a number or requirements enlisted for the programming real-time electricity usage monitoring tool (Watts Up Pro (wup), 11 languages. We decided to chose the top 15 programming languages and 3) embedded device (Raspberry Pi 3b). enlisted for June 2017. From the current list, we excluded program- In general, there are two venues for retrieving energy consump- ming languages such as Delphi (not available for Linux OS we are tion from a computer-based system. On the one hand, this is achiev- using) and Assembly (different implementations between processor able by indirect energy measurements through estimation models architectures). In contrast, we included Rust in our dataset that is or performance counters, core component of software monitor- a memory safe programming language and is gaining vast popu- ing tools. On the other hand, it is done via direct measurement, larity in the web. Therefore, we ended up with 14 programming hardware power analyzers and sensors. However, each of these languages as it is illustrated in Table 1. approaches has its own pitfalls. The direct approach , i.e., hardware To select the examined tasks, we developed a shell script (see components, offers coarse-grained measurements for the whole Subsection 2.2.2) to identify which of the 851 tasks offer the most systems’ energy consumption and low sampling rate.