Energy Consumption Measurement of Algorithms with Rhino #1455
StSchnell
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This post describes the use of jPowerMonitor for measuring energy consumption of JavaScript algorithms with Rhino. jPowerMonitor is a JUnit extension and Java agent for energy consumption measurement from msg systems from Hans-Peter Keilhofer aka @keilhofh and Jakob Deiner aka @deinerj. The use of jPowerMonitor is very well described. Here we focus on usage in the context of Rhino.
What is Green IT and Green Coding?
Green IT is a generic term and describes the practice of environmentally friendly procurement, use and disposal of computer resources. Green coding is a subset of this and is about sustainable programming. Among other things the target here is to achieve the lowest possible energy consumption. This is another non-functional programming requirement. Because each line of code has the potential to reduce energy and resource consumption. This reduces emissions and saves raw materials.
jPowerMonitor with Rhino
Rhino is part of many products in business. For precisely this reason it can be valuable to look at this. To detect which code sequences and algorithms have which energy consumption, we can use jPowerMonitor for analysis with Rhino. Here we use jPowerMonitor as a Java agent. It is important not to use Rhino in interpretative mode, it is necessary to compile the JavaScript source code into a class. The following batch file can be used to perform an analysis:
It compiles the JavaScript source to a class and invoke this class with jPowerMonitor as agent.
Example Code to be Analyzed
In the following example four sorting algorithms are compared and their energy consumption determined.
The example code contains a class for generating random numbers and four functions that contain the specific sorting algorithm. In the main function they are called sequentially and the execution time is measured.
Result of the Example
By calling the JavaScript code and measure it, the following result is displayed or similar:
jPowerMonitor creates a file with the prefix jPowerMonitor in the name and the tail energy_per_method.csv. This files contains a list with the energy consumption of each method of the JavaScript source. After sorting the energy consumption in descending order, it looks like this, for example:
The calls of the sorting algorithms and their results are clearly visible.
It is important to ensure that no other activities are executed out on the computer.
Conclusion
jPowerMonitor is a great library. In the context of JavaScript with the Rhino engine it delivers interesting information about the energy consumption of functions and methods at program execution. However, one disadvantage is that Rhino cannot provide this information in interpretive mode. If a platform uses this mode, this approach can unfortunately not be used. In this case the measurements must be perform on reference systems. But that provides also valuable clues.
Beta Was this translation helpful? Give feedback.
All reactions