Analyzing the Time x Energy Relation in C++ Solutions Mined from a Programming Contest Site

  • Sérgio Queiroz de Medeiros UFRN
  • Marcelo Borges Nogueira UFRN
  • Gustavo Quezado Gurgel Magalhães UFRN


The current concern about global warming has led to an increasing interest in the energy efficiency of computer applications. Assuming power is constant, the general trend is that faster programs will consume less energy, thus optimizing a program for speed would also improve its energy efficiency. We investigate this tendency in a set of C++ solutions mined from CSES (Code Submission Evaluation System), a popular programming competition site. Each CSES problem has several test cases, where a test case consists of a given input and its corresponding output. In order to be considered correct, the C++ solution of a user for a given problem must give for each of its test cases, under a given time limit, the expected answer. In such context, we can consider that all correct solutions for a problem were written with a speed concern, but not with energy efficiency in mind. We selected 15 problems from CSES and for each of them we mined 30 C++ solutions, trying to select the faster and the slower ones, as also some randomly chosen solutions. Then, we evaluated the time and energy efficiency of each solution in two different machines. In our scenario, where there is a great diversity of programming styles, execution speed and memory usage, we could confirm the general trend, where the faster programs consume less energy. Moreover, by using the least square method, we were able to predict with good precision the energy consumption of a program based on its execution time. A manual analysis of the programs with unexpected energy consumption revealed that often their memory usage is different when compared to programs with similar execution times. Besides helping to confirm that faster programs usually are more energy-efficient than slower ones, our results seem to indicate that our approach to predict the energy consumption of a program can help to automatically identify programs with abnormal energy consumption. Finally, our test framework, which comprises the benchmark with 450 C++ programs, the analysis script and the test results, is publicly available.
Palavras-chave: C , compiler optimizations, energy efficiency, programming competitions
MEDEIROS, Sérgio Queiroz de; NOGUEIRA, Marcelo Borges; MAGALHÃES, Gustavo Quezado Gurgel. Analyzing the Time x Energy Relation in C++ Solutions Mined from a Programming Contest Site. In: SIMPÓSIO BRASILEIRO DE LINGUAGENS DE PROGRAMAÇÃO (SBLP), 27. , 2023, Campo Grande/MS. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2023 . p. 64–72.