You are on page 1of 5

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/282364730

Energy Consumption Analysis of Algorithms Implementations

Conference Paper · October 2015


DOI: 10.1109/ESEM.2015.7321198

CITATIONS READS
13 426

3 authors:

Mohammad Rifat Ahmmad Rashid Luca Ardito


Politecnico di Torino Politecnico di Torino
10 PUBLICATIONS   19 CITATIONS    28 PUBLICATIONS   251 CITATIONS   

SEE PROFILE SEE PROFILE

Marco Torchiano
Politecnico di Torino
190 PUBLICATIONS   2,631 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

ASPIRE-FP7 View project

ASPIRE View project

All content following this page was uploaded by Marco Torchiano on 02 October 2015.

The user has requested enhancement of the downloaded file.


Energy Consumption Analysis of
Algorithms Implementations
Mohammad Rashid, Luca Ardito, and Marco Torchiano
Politecnico di Torino
Department of Control and Computer Engineering, Turin, Italy
Email: name.surname@polito.it

Abstract—Context: Mobile devices, typically battery driven, they only presented a theoretical explanation by using staple
require new efforts to improve the energy efficiency of both algorithms such as random number generation and sorting to
hardware and software designs. verify the model.
Goal: The goal of this work is to analyze the energy efficiency
of different sorting algorithms implementations. Bunse et al. [2] examined energy efficient sorting algorithms
Method: We set up an experiment on an ARM based device, and, based on experimental result, they presented an approach
measuring the energy consumption of different sorting algorithms for saving energy by choosing the appropriate sorting algo-
implemented in different programming languages. rithm. Based on an abstract memory model in [3] Roy et al.,
Result: The algorithms and languages exhibit significantly presented a energy model that is a (weighted) sum of the time
different energy consumption, the ARM assembly language
implementation of Counting sort is the greenest solution.
complexity of the algorithm and the number of ”parallel” I/O
Conclusion: We provide the basic information to select al- accesses made by the algorithm. Energy efficient sorting was
gorithms, and we identified the main factors affecting energy explored in [4], where authors proposed an external sorting
consumption. benchmark for evaluating the energy efficiency of a wide range
of systems. But this benchmark was more focused on hardware
I. I NTRODUCTION criteria rather than exploring the software domain.
With the increasing popularity of mobile and embedded Relatively little work focuses on understanding energy con-
systems, energy management has become a critical challenge. sumption in algorithm implementation. In [5] authors exam-
Mobile devices are typically battery driven, and the impor- ined the effects of compiler energy optimization with different
tance of energy efficiency has led to rethink hardware and levels of architectural optimization. But this study only focus
software designs. However algorithm design is still relatively on GCC Compiler Optimization of embedded systems.
untouched, as a matter of fact complexity models do not The contribution of this paper is to analyze algorithm
consider the energy consumed by an algorithm. implementation energy efficiency. Therefore in our study we
Current mobile and embedded devices run programs written performed experiments aimed at accessing energy impact of
with different programming languages. For this reason it is algorithm execution using different programming languages
also important to consider how energy efficient is a software (ARM assembly, C, Java).
written with a particular programming language.
III. E XPERIMENT D ESIGN
Thus it is important to analyze the algorithm energy effi-
ciency (in theory), and its implementation energy efficiency The aim of our research is to compare the impact of some
(in practice) because nowadays we only know the impact in sorting algorithms with different computational complexity
terms of memory usage and execution time. with regard to energy consumption. For this purpose we
To do so, we will focus on sorting algorithms because they used a ARM-based device: a Raspberry Pi. We performed
are well known with regard to complexity and implementation. an experiment, which measures the energy consumed by
The remainder of this paper is structured as follows: Section different sorting algorithm over three different languages ARM
II introduces the related work, Section III describes the context assembly, C and Java. The choice of different languages allows
of our work, including instrumentation and research ques- us to evaluate the trade-offs deriving from increasing coding
tions, Section IV presents results while Section V discusses abstraction levels.
them and, finally, Section VI provides conclusions and future A. Goal Description and Research Questions
works. We define our goal through the Goal-Question-Metric
II. R ELATED W ORK (GQM) approach [6]. This approach, applied to our experi-
ment, leads to the definition of the model presented in Table
Recent research efforts has been spent on analyzing al- I.
gorithms energy efficiency with regard to time and space
complexity. Energy-aware algorithms have previously been B. Variable selection
examined by Jain et al. in [1]. In this paper authors defined a For this experiment we selected three independent variables,
theoretical algorithm complexity model for energy. However or factors:
TABLE I RQ3 focuses on the relationship between energy and mem-
T HE GQM M ODEL FOR OUR EXPERIMENT ory usage. In particular we investigate the caching , branching
and instructions per cycle for each task. We formulate the null
Analyze different algorithms hypothesis as:
for the purpose assessing differences
Goal of Hm0 there is a null correlation between memory usage (i.e.
with respect to energy consumption cache, branch and instructions) and energy consumed
the context of a Raspberry Pi
to perform the task.
RQ 1 Does different programming languages consume different
amount of energy for executing the same algorithm? D. Instrumentation and Experiment Design
Metric Ei Energy consumed The selected usage scenarios have been implemented in
RQ 2 Are energy consumption and computational performance cor- ARM, C, and Java language. In order to obtain a statistically
related? relevant data set, we created a task for each data size and
Metric Ei vs ti Energy consumed language composed of five repetition of the same sorting
RQ 3 How does memory management affect energy consumption algorithm, and each task has been repeated 30 times.
for executing different algorithms? 1) Hardware Instrumentation: The experiment has been
Metric Ei Energy consumed by memory usages performed on a Raspberry Pi running the Raspbian Linux
distribution.
The energy consumption data was acquired through a NI
USB-6210 1 DAQ. With this device we get current with a
• Language: the type of programming language used to sampling frequency of 1kHz, and it is placed between the
implement the algorithm, ∈ {ARM Assembly, C, Java} power source and the Raspberry Pi. The NI USB-6210 sends
• Algorithm: the specific sorting algorithm used in the the collected data to a laptop.
experiment , ∈ {Bubble, Merge, Quick, Counting} 2) Software Setup: We separate one single execution from
• Data Size: the number of integer elements to sort used another with a sleep and a while(1) loop, which last a
in the algorithm execution, ∈ {10,000, 50,000, 100,000} predefined amount of time. By doing this we created tags in
In addition we collected a few indexes that characterize the our collected data because the sleep has the lowest energy
behavior of the CPU and the memory management: consumption value, while the while(1) loop has the highest
• IPC: instructions per cycle. ∈ [0, 1] energy consumption value.
• PCT CM: percentage of cache miss, ∈ [0, 1] The sleep power consumption value is subtracted from
• PCT BM: percentage of branch miss, ∈ [0, 1] the task power to obtain the actual power consumed by the
algorithm execution.
For each language, algorithm, and dataset we run 30 times a
We used Perf profiler2 for collecting memory performance
task, which runs five times the sorting algorithm. During each
on each task execution.
execution we collected a set of measure (dependent variables)
that consist of the energy consumed (E), the average power E. Analysis Methodology
used (P ) and the time taken by the algorithm to complete each
Considering the first hypothesis (He0 ) we check the
task (t). We also collected the memory usages data for each
distribution of energy based on these factors: Language,
code execution.
Algorithm and DataSize. In practice we check the relation-
C. Hypotheses Formulation ship between Energy vs. time according to the fundamental
relationship: E = P · t.
We formalized our Research Questions into hypotheses
In addition for (Ht0 ) and (Hc0 ),we investigate the effects of
based on our GQM Model. RQ1, focuses on the energy
the independent factors on the task average power consump-
consumption of algorithm implementations using different
tion. For this purpose we fit a linear model based on task per
languages. We formulate the null hypothesis as:
different DataSize, Language and Algorithm. Regression
He0 the factors have no significant effect on the energy is based on the following linear regression equation:
used for the task execution.
RQ2 focuses on the relationship between energy consump- P ower = ctime · time + cN · N cBubble · iBubble +
tion and computational performance. In particular we inves- cCounting · iCounting + cM erge · iM erge + (1)
tigate the correlation between energy and time, and between cQuick · iQuick + cC · iC + cJava · iJava
power and Language, Algorithm and Dataset. We formulate Where iX is an indicator variable for a specific level of a
the following null hypotheses as: factor, e.g. iBubble is an indicator variable for level Bubble of
Ht0 there is a null correlation between time and energy factor Algorithm. Indicator variables are equal to 1 when the
consumed to perform the task.
1 http://sine.ni.com/nips/cds/view/p/lang/en/nid/203223 Last Visited 06 June
Hc0 the factors (i.e. language, algorithm, dataset) have no
2015
significant effect on the power used during the tasks 2 https://perf.wiki.kernel.org/index.php/Main Page Last Visited 06 June
execution. 2015
factor assumes the relative level and 0 otherwise. We added
the time factor to verify that time has no effect on power.
We observe that, for the first factor in the equation (i.e. Lan-
guage) we report the indicator variables for all levels, while
for the second factor we report the indicator variable for two
out of three levels because the coefficient for the first level is
implicit.
Concerning the hypothesis(Hm0 ) our work explores the
effect of memory management for each task execution. In
particular we perfom a regression of Power vs. the HW
indexes, IPC, PCT CM, and PCT BM.
F. Threats to validity
We can identify a few different threats, which could affect
the validity of our experimental results.
The first threat is related to the energy consumed by the
operating system (I/O, process scheduling, etc.), which may
alter the energy measures. We computed the “idle” energy
consumption and then we subtracted it to our measurements
in order to obtain the energy consumption due to the sole
sorting algorithm task. The second threat is related to the
management of unnecessary signals as noise. To overcome this
problem we use low pass filter with cutoff frequency 40Hz to
reduce signal noise. And finally the absolute values of energy
and power consumption are specific to a single device, though
they are representatives of a very popular category of devices
with similar specifications3 . We expect to find similar trends
and ratios in devices, e.g. mobile phones, which use similar
ARM-based processor architectures. The statistical analyses
we conducted assume that all experiments are independent: in
our setup the array is re-initialized before every sort execution,
and when distinct process executions are isolated from each
other because no permanent storage is used.
Fig. 1. Power and Energy for all configurations
IV. R ESULTS
The distributions of the average power and total energy per
different size, algorithm, and language are shown in Figure 1 TABLE II
by means of boxplots. According to a Kruskal-Wallis test the R EGRESSION OF P OWER VS . FACTORS .
three factors have a significant effect on Energy ( p<0.001 in
Estimate Std. Error t value Pr(>|t|)
all cases), as we can visually observe in the Figure.
Concerning the relationship between time and energy, first time -3.3e-06 1e-05 -0.31 0.75
of all we fit a regression equation of Energy vs. time, according N 5.6e-07 2.3e-0.8 24 <0.001
to the fundamental relationship: AlgorithmBubble 0.137 0.0027 51 <0.001
AlgorithmCounting 0.119 0.0023 52 <0.001
Energy = P ower · time AlgorithmMerge 0.107 0.0023 47 <0.001
The regression estimates the coefficient Power = 0.158, it AlgoritmQuick 0.105 0.0023 46 <0.001
is significant (p<0.01); overall the regression R2 = 89.1%. LanguageC -0.033 0.002 -17 <0.001
The coefficients and the relative significance levels for the LanguageJava 0.036 0.0019 19 <0.001
regression of Power vs. time, Algorithm, Language, and N are
reported in Table II.
As expected, time is not significant at all. The size of
the array has a negligible, though statistically significant
coefficient. The algorithms have different coefficients ranging To understand the main causes of the effect of the Language
from 0.105 for AlgorithmQuick to 0.137 for AlgorithmBubble. and Algorithm factors, we performed a regression of Power
vs. the HW indexes. The coefficient and statistical significance
3 http://goo.gl/Zfltcx Last Visited 06 June 2015 are reported in Table III.
TABLE III
R EGRESSION OF P OWER VS . HW INDEXES

Estimate Std. Error t value Pr(>|t|)


(Intercept) 0.1444 0.0129 11.22 <0.001
IPC 0.0039 0.0158 0.25 0.8033
PCT CM 2.6332 0.1255 20.99 <0.001
PCT BM -0.1471 0.0421 -3.49 <0.001

We observe that the both the percentage of cache misses and


that of branch misses are statistically significant predictors,
while the instructions per cycle is not.
V. D ISCUSSION
As expected, we obtained different levels of energy con-
sumption for different algorithms and languages.
Fig. 2. Power vs Time for different factor levels.
We have a good linear regression of Energy vs. time. The
percentage explained by the sole duration of the task is slightly
more than 89%. The residuals can be explained in terms VI. C ONCLUSIONS AND F UTURE W ORKS
of different (average) power consumption by the different
We analyzed the energy and power consumption of dif-
algorithms and languages.
ferent sorting algorithms and the relative implementation in
By looking at the upper part of Figure 1 we can observe that
three distinct languages. Both the algorithm and the language
among algorithms, Counting sort exhibits better performances,
significantly affect the total energy consumption.
followed by Quicksort. We did not run Bubble sort on the
A large part of the energy consumed is determined by
largest array because it would be absolutely non comparable.
the time performance, i.e. computational complexity of the
Concerning the language performance, we observe a consis-
solution, though roughly 10% is determined by a specific
tent ranking with ARM assembly as the least energy hungry
power consumption pattern.
language and Java as the most energy hungry.
Our study provides the basic information to chose a specific
Looking at the (average) power during task (bottom diagram
sorting implementation to minimize energy consumption.
in Figure 1) we observe a similar order among algorithms as
As further work we plan investigating in more details the
for energy. This visual analysis is confirmed by the coefficients
hardware factors that affect energy consumption and how they
relative to the four algorithms in the regression reported in
are related to specific language idioms.
Table II.
By looking at the coefficients in Table II we observe R EFERENCES
that the effect of languages on average power is roughly an [1] R. Jain, D. Molnar, and Z. Ramzan, “Towards understanding algorithmic
order of magnitude smaller than the algorithm. In particular factors affecting energy consumption: Switching complexity, randomness,
language C appears more efficient than ARM which, in turn, and preliminary experiments,” in Proceedings of the 2005 Joint Workshop
on Foundations of Mobile Computing, ser. DIALM-POMC ’05. New
is more efficient than Java. This order is different from the York, NY, USA: ACM, 2005, pp. 70–79. [Online]. Available:
one observed for the total energy, where ARM is consistently http://doi.acm.org/10.1145/1080810.1080823
smaller than C. [2] C. Bunse, H. Hopfner, E. Mansour, and S. Roychoudhury, “Exploring
the energy consumption of data sorting algorithms in embedded and
An overall view of the above results can be obtained by mobile environments,” in Mobile Data Management: Systems, Services
looking at how the median values of the dependent variables and Middleware, 2009. MDM ’09. Tenth International Conference on,
(for each combination of factor levels) as shown in Figure 2. May 2009, pp. 600–607.
[3] S. Roy, A. Rudra, and A. Verma, “An energy complexity
We can observe that while in terms of time ARM is model for algorithms,” in Proceedings of the 4th Conference on
consistently smaller than C, it often exhibits a higher (average) Innovations in Theoretical Computer Science, ser. ITCS ’13. New
power consumption. York, NY, USA: ACM, 2013, pp. 283–304. [Online]. Available:
http://doi.acm.org/10.1145/2422436.2422470
The different power consumption can be explained mainly [4] S. Rivoire, M. A. Shah, P. Ranganathan, and C. Kozyrakis, “Joulesort:
by means of the the PCT CM that has the largest coefficient A balanced energy-efficiency benchmark,” in Proceedings of the 2007
(see Table III). The task executed with the three languages ACM SIGMOD International Conference on Management of Data, ser.
SIGMOD ’07. New York, NY, USA: ACM, 2007, pp. 365–376.
actually exhibit different median values for such indicator: [Online]. Available: http://doi.acm.org/10.1145/1247480.1247522
0.17% for ARM, 0.11% for C and 0.86% for Java. Partially [5] S. Daud, R. Ahmad, and N. Murhty, “The effects of compiler optimiza-
counter-intuitive is the negative sign for the the PCT BM tions on embedded system power consumption,” in Electronic Design,
2008. ICED 2008. International Conference on, Dec 2008, pp. 1–6.
coefficient. We speculate that a larger number of branch [6] R. Van Solingen and E. Berghout, Goal/Question/Metric Method.
misses slows down the processor, therefore lowering the power McGraw-Hill Inc.,US, January 1999.
consumption.

View publication stats

You might also like