98
How Green are Java Best Practices? Best Coding Practices and Software Eco-Design Jérôme Rocheteau Institut Catholique d’Arts et Métiers, Nantes, France GreenDays@Rennes – Mardi 1 er juillet 2014 How Green are Java Best Practices? GreenDays | 2014-07-01 1 / 33

How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Embed Size (px)

DESCRIPTION

This work investigates if best coding practices in Java can stand for eco-design rules as they deal with software performance. It focuses on how validating such an hypothesis for consumed energy, spent execution time and peak allocated memory. It leads to this silent feedback: no need to carry on many measures.

Citation preview

Page 1: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

How Green are Java Best Practices?Best Coding Practices and Software Eco-Design

Jérôme Rocheteau

Institut Catholique d’Arts et Métiers, Nantes, France

GreenDays@Rennes – Mardi 1er juillet 2014

How Green are Java Best Practices? GreenDays | 2014-07-01 1 / 33

Page 2: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Overview

1 Eco-Design and Best Practices

2 Formalizing Practices

3 Measuring Codes

4 Analyzing Measures, Codes, Practices

5 Eco-Design Indicators

How Green are Java Best Practices? GreenDays | 2014-07-01 2 / 33

Page 3: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design and Best Practices

1 Eco-Design and Best Practices

Context and Issues

Hypothesis and Objectives

2 Formalizing Practices

3 Measuring Codes

4 Analyzing Measures, Codes, Practices

5 Eco-Design Indicators

How Green are Java Best Practices? GreenDays | 2014-07-01 3 / 33

Page 4: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Context and Issues

Context:

ICT accounted 2% of carbon emissions in 2007Energy efficiency relies on hardware but not softwareWorks on energy efficiency classes, energy-aware systems

Issues:

Help developers to build energy-efficient software1 Detect energy-consuming patterns in source code2 Replace these patterns by energy-saving ones

Qualify the energy impact for such best practices

How Green are Java Best Practices? GreenDays | 2014-07-01 4 / 33

Page 5: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Hypothesis and Objectives

HypothesisBest coding practices are eco-design rules

Objectives:

1 Formalizing Java best practices2 Measuring savings of memory and energy at runtime3 Evaluating confidence of such results

How Green are Java Best Practices? GreenDays | 2014-07-01 5 / 33

Page 6: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Formalizing Practices

1 Eco-Design and Best Practices

2 Formalizing Practices

Informal and Formal Examples

Time, Space, Energy Semantics

3 Measuring Codes

4 Analyzing Measures, Codes, Practices

5 Eco-Design Indicators

How Green are Java Best Practices? GreenDays | 2014-07-01 6 / 33

Page 7: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Best Coding Practice Example / Informal Rule:

String Literal InitializationInitialization of strings with the keyword ’new’ creates newobjects. This is costly in time and memory space. Initializationswith literal strings avoids this.

Three shape of Java best coding practices :1 Prefer this2 Avoid that3 Replace that by this

Can be extended to other primitive/wrapper typesCan be applied to other programming languages

How Green are Java Best Practices? GreenDays | 2014-07-01 7 / 33

Page 8: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Best Coding Practice Example / Informal Rule:

String Literal InitializationInitialization of strings with the keyword ’new’ creates newobjects. This is costly in time and memory space. Initializationswith literal strings avoids this.

Three shape of Java best coding practices :1 Prefer this2 Avoid that3 Replace that by this

Can be extended to other primitive/wrapper typesCan be applied to other programming languages

How Green are Java Best Practices? GreenDays | 2014-07-01 7 / 33

Page 9: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Best Coding Practice Example / Informal Rule:

String Literal InitializationInitialization of strings with the keyword ’new’ creates newobjects. This is costly in time and memory space. Initializationswith literal strings avoids this.

Three shape of Java best coding practices :1 Prefer this2 Avoid that3 Replace that by this

Can be extended to other primitive/wrapper types

Can be applied to other programming languages

How Green are Java Best Practices? GreenDays | 2014-07-01 7 / 33

Page 10: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Best Coding Practice Example / Informal Rule:

String Literal InitializationInitialization of strings with the keyword ’new’ creates newobjects. This is costly in time and memory space. Initializationswith literal strings avoids this.

Three shape of Java best coding practices :1 Prefer this2 Avoid that3 Replace that by this

Can be extended to other primitive/wrapper typesCan be applied to other programming languages

How Green are Java Best Practices? GreenDays | 2014-07-01 7 / 33

Page 11: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Best Coding Practice Example / Informal Rule:

String Literal InitializationInitialization of strings with the keyword ’new’ creates newobjects. This is costly in time and memory space. Initializationswith literal strings avoids this.

Three shape of Java best coding practices :1 Prefer this2 Avoid that3 Replace that by this

Can be extended to other primitive/wrapper typesCan be applied to other programming languages

How Green are Java Best Practices? GreenDays | 2014-07-01 7 / 33

Page 12: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Listing 1: Prefer String Literal Initialization<rule id="prefer-string-literal-initialization">

<title>Prefer string literal initialization</title><description>

Primitive type objects should be initialized with primitive valuesand without the use of any constructors.

</description><check green="StringValue" gray="StringObject" />

</rule>

How Green are Java Best Practices? GreenDays | 2014-07-01 8 / 33

Page 13: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Listing 2: String Literal Initializationp u b l i c c l a s s S t r i n g V a l u e implements Code {

p r i v a t e S t r i n g [ ] a r r a y ;

p u b l i c vo id setUp ( ) {a r r a y = new S t r i n g [ 1 0 0 0 ] ;

}

p u b l i c vo id doRun ( ) throws Excep t i on {f o r ( i n t i = 0 ; i < 1000 ; i ++) {

a r r a y [ i ] = " abcde fg . . . " ;}

}

p u b l i c vo id tearDown ( ) {a r r a y = n u l l ;

}

}

How Green are Java Best Practices? GreenDays | 2014-07-01 9 / 33

Page 14: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Informal and Formal Examples

Listing 3: String Object Initializationp u b l i c c l a s s S t r i n g O b j e c t implements Code {

p r i v a t e S t r i n g [ ] a r r a y ;

p u b l i c vo id setUp ( ) {a r r a y = new S t r i n g [ 1 0 0 0 ] ;

}

p u b l i c vo id doRun ( ) throws Excep t i on {f o r ( i n t i = 0 ; i < 1000 ; i ++) {

a r r a y [ i ] = new S t r i n g ( " abcde fg . . . " ) ;}

}

p u b l i c vo id tearDown ( ) {a r r a y = n u l l ;

}

}

How Green are Java Best Practices? GreenDays | 2014-07-01 10 / 33

Page 15: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

Prefer LiteralInitialization

time = ft(td , tc)space = fs(sd , sc)energy = fe(ed , ec)

How Green are Java Best Practices? GreenDays | 2014-07-01 11 / 33

Page 16: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

String ValueInitialization

Prefer LiteralInitialization

String ObjectInitialization

time = ft(td , tc)space = fs(sd , sc)energy = fe(ed , ec)

How Green are Java Best Practices? GreenDays | 2014-07-01 11 / 33

Page 17: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

String ValueInitialization

Prefer LiteralInitialization

String ObjectInitialization

time tcspace scenergy ec

time tdspace sdenergy ed

time = ft(td , tc)space = fs(sd , sc)energy = fe(ed , ec)

How Green are Java Best Practices? GreenDays | 2014-07-01 11 / 33

Page 18: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

String ValueInitialization

Prefer LiteralInitialization

String ObjectInitialization

time tcspace scenergy ec

time tdspace sdenergy ed

time = ft(td , tc)space = fs(sd , sc)energy = fe(ed , ec)

How Green are Java Best Practices? GreenDays | 2014-07-01 11 / 33

Page 19: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

Goal: statistical static analysis method and tools

original code

How Green are Java Best Practices? GreenDays | 2014-07-01 12 / 33

Page 20: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

Goal: statistical static analysis method and tools

original code

How Green are Java Best Practices? GreenDays | 2014-07-01 12 / 33

Page 21: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

Goal: statistical static analysis method and tools

original code refactored code

How Green are Java Best Practices? GreenDays | 2014-07-01 12 / 33

Page 22: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Time, Space, Energy Semantics

Goal: statistical static analysis method and tools

original code refactored code

possible savingsX joules / X %

How Green are Java Best Practices? GreenDays | 2014-07-01 12 / 33

Page 23: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measuring Codes

1 Eco-Design and Best Practices

2 Formalizing Practices

3 Measuring Codes

Needs and Requirements

Measure Task and Process

4 Analyzing Measures, Codes, Practices

5 Eco-Design Indicators

How Green are Java Best Practices? GreenDays | 2014-07-01 13 / 33

Page 24: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Needs and Requirements

Needs:

power-meter with digital outputsmemory monitor with digital outputsplatform for running Java codessystem for managing codes and measures

Requirements:

power-meter with fine-grain precisionJava micro-benchmarking to avoid JITsystem able to manage physical and logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 14 / 33

Page 25: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Needs and Requirements

Needs:

power-meter with digital outputs

memory monitor with digital outputsplatform for running Java codessystem for managing codes and measures

Requirements:

power-meter with fine-grain precision

Java micro-benchmarking to avoid JITsystem able to manage physical and logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 14 / 33

Page 26: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Needs and Requirements

Needs:

power-meter with digital outputsmemory monitor with digital outputs

platform for running Java codessystem for managing codes and measures

Requirements:

power-meter with fine-grain precision

Java micro-benchmarking to avoid JITsystem able to manage physical and logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 14 / 33

Page 27: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Needs and Requirements

Needs:

power-meter with digital outputsmemory monitor with digital outputsplatform for running Java codes

system for managing codes and measures

Requirements:

power-meter with fine-grain precisionJava micro-benchmarking to avoid JIT

system able to manage physical and logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 14 / 33

Page 28: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Needs and Requirements

Needs:

power-meter with digital outputsmemory monitor with digital outputsplatform for running Java codessystem for managing codes and measures

Requirements:

power-meter with fine-grain precisionJava micro-benchmarking to avoid JITsystem able to manage physical and logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 14 / 33

Page 29: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessMeasurement Protocol:

1 4 seconds idle2 10 seconds execution time3 3 seconds idle

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 30: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessSemantics based on quantitative metrics:

x-axis execution timey-axis instant power or instant memory space

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 31: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessPreliminary Computations:

total energy obtained by the trapezoidal ruleidle power = average of the first 4 second instant powersidle energy = idle power × protocol time

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 32: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessPreliminary Computations:

total energy obtained by the trapezoidal rule

idle power = average of the first 4 second instant powersidle energy = idle power × protocol time

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 33: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessPreliminary Computations:

total energy obtained by the trapezoidal ruleidle power = average of the first 4 second instant powers

idle energy = idle power × protocol time

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 34: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessPreliminary Computations:

total energy obtained by the trapezoidal ruleidle power = average of the first 4 second instant powersidle energy = idle power × protocol time

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 35: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessCode energy computation and normalization:

code energy = total energy - idle energy

normalized code energy = code energy / times of execution

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 36: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and ProcessCode energy computation and normalization:

code energy = total energy - idle energynormalized code energy = code energy / times of execution

How Green are Java Best Practices? GreenDays | 2014-07-01 15 / 33

Page 37: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and Process

Measure Process:

1 Retrieve an available Java code2 Iterate while this code isn’t mature:

Clean its measure setCompute its maturityPlan new measures if requiredPerform these measures

3 Send the report of this code

How Green are Java Best Practices? GreenDays | 2014-07-01 16 / 33

Page 38: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and Process

Measure Process:

1 Retrieve an available Java code

2 Iterate while this code isn’t mature:

Clean its measure setCompute its maturityPlan new measures if requiredPerform these measures

3 Send the report of this code

How Green are Java Best Practices? GreenDays | 2014-07-01 16 / 33

Page 39: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and Process

Measure Process:

1 Retrieve an available Java code2 Iterate while this code isn’t mature:

Clean its measure setCompute its maturityPlan new measures if requiredPerform these measures

3 Send the report of this code

How Green are Java Best Practices? GreenDays | 2014-07-01 16 / 33

Page 40: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and Process

Measure Process:

1 Retrieve an available Java code2 Iterate while this code isn’t mature:

Clean its measure set

Compute its maturityPlan new measures if requiredPerform these measures

3 Send the report of this code

How Green are Java Best Practices? GreenDays | 2014-07-01 16 / 33

Page 41: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and Process

Measure Process:

1 Retrieve an available Java code2 Iterate while this code isn’t mature:

Clean its measure setCompute its maturity

Plan new measures if requiredPerform these measures

3 Send the report of this code

How Green are Java Best Practices? GreenDays | 2014-07-01 16 / 33

Page 42: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and Process

Measure Process:

1 Retrieve an available Java code2 Iterate while this code isn’t mature:

Clean its measure setCompute its maturityPlan new measures if required

Perform these measures3 Send the report of this code

How Green are Java Best Practices? GreenDays | 2014-07-01 16 / 33

Page 43: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Measure Task and Process

Measure Process:

1 Retrieve an available Java code2 Iterate while this code isn’t mature:

Clean its measure setCompute its maturityPlan new measures if requiredPerform these measures

3 Send the report of this code

How Green are Java Best Practices? GreenDays | 2014-07-01 16 / 33

Page 44: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Analyzing Measures, Codes, Practices

1 Eco-Design and Best Practices

2 Formalizing Practices

3 Measuring Codes

4 Analyzing Measures, Codes, Practices

Clean and Canonical Measures

Code Maturity

Results

5 Eco-Design IndicatorsHow Green are Java Best Practices? GreenDays | 2014-07-01 17 / 33

Page 45: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures3 kinds of measure disturbances:

disturbances before the measure task underestimatedisturbances after the measure task overestimatedisturbances during the measure task overestimate

How Green are Java Best Practices? GreenDays | 2014-07-01 18 / 33

Page 46: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures3 kinds of measure disturbances:

disturbances before the measure task underestimate

disturbances after the measure task overestimatedisturbances during the measure task overestimate

How Green are Java Best Practices? GreenDays | 2014-07-01 18 / 33

Page 47: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures3 kinds of measure disturbances:

disturbances before the measure task underestimatedisturbances after the measure task overestimate

disturbances during the measure task overestimate

How Green are Java Best Practices? GreenDays | 2014-07-01 18 / 33

Page 48: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures3 kinds of measure disturbances:

disturbances before the measure task underestimatedisturbances after the measure task overestimatedisturbances during the measure task overestimate

How Green are Java Best Practices? GreenDays | 2014-07-01 18 / 33

Page 49: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

3 kinds of measure disturbances:

disturbances before the measure taskdisturbances after the measure taskdisturbances during the measure task

2 mere algorithms for cleaning measures:

bounds checking algorithm (over a single measure)split-and-merge algorithm (over a set of measures)

How Green are Java Best Practices? GreenDays | 2014-07-01 19 / 33

Page 50: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

3 kinds of measure disturbances:

disturbances before the measure taskdisturbances after the measure taskdisturbances during the measure task

2 mere algorithms for cleaning measures:

bounds checking algorithm (over a single measure)

split-and-merge algorithm (over a set of measures)

How Green are Java Best Practices? GreenDays | 2014-07-01 19 / 33

Page 51: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

3 kinds of measure disturbances:

disturbances before the measure taskdisturbances after the measure taskdisturbances during the measure task

2 mere algorithms for cleaning measures:

bounds checking algorithm (over a single measure)split-and-merge algorithm (over a set of measures)

How Green are Java Best Practices? GreenDays | 2014-07-01 19 / 33

Page 52: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

Cleaning algorithm evaluation:

500 clean measures from 25 rules annotated by 3 experts

inter-agreement κ: 0.94 (almost perfect)baseline = quartile method

precision: 0.953recall: 0.911

split-and-merge algorithmprecision: 0.941recall: 1.0

remove all disturbed measures

How Green are Java Best Practices? GreenDays | 2014-07-01 20 / 33

Page 53: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

Cleaning algorithm evaluation:

500 clean measures from 25 rules annotated by 3 expertsinter-agreement κ: 0.94 (almost perfect)

baseline = quartile methodprecision: 0.953recall: 0.911

split-and-merge algorithmprecision: 0.941recall: 1.0

remove all disturbed measures

How Green are Java Best Practices? GreenDays | 2014-07-01 20 / 33

Page 54: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

Cleaning algorithm evaluation:

500 clean measures from 25 rules annotated by 3 expertsinter-agreement κ: 0.94 (almost perfect)baseline = quartile method

precision: 0.953recall: 0.911

split-and-merge algorithmprecision: 0.941recall: 1.0

remove all disturbed measures

How Green are Java Best Practices? GreenDays | 2014-07-01 20 / 33

Page 55: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

Cleaning algorithm evaluation:

500 clean measures from 25 rules annotated by 3 expertsinter-agreement κ: 0.94 (almost perfect)baseline = quartile method

precision: 0.953recall: 0.911

split-and-merge algorithmprecision: 0.941recall: 1.0

remove all disturbed measures

How Green are Java Best Practices? GreenDays | 2014-07-01 20 / 33

Page 56: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical Measures

Cleaning algorithm evaluation:

500 clean measures from 25 rules annotated by 3 expertsinter-agreement κ: 0.94 (almost perfect)baseline = quartile method

precision: 0.953recall: 0.911

split-and-merge algorithmprecision: 0.941recall: 1.0remove all disturbed measures

How Green are Java Best Practices? GreenDays | 2014-07-01 20 / 33

Page 57: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical MeasuresCanonical measure:

How Green are Java Best Practices? GreenDays | 2014-07-01 21 / 33

Page 58: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical MeasuresCanonical measure:

time: t3space: s3energy: e3

time: t2space: s2energy: e2

time: t1space: s1energy: e1

How Green are Java Best Practices? GreenDays | 2014-07-01 21 / 33

Page 59: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical MeasuresCanonical measure:

time: t3space: s3energy: e3

time: t2space: s2energy: e2

time: t1space: s1energy: e1

time: tspace: senergy: e

How Green are Java Best Practices? GreenDays | 2014-07-01 21 / 33

Page 60: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical MeasuresCanonical measure:

time: t3space: s3energy: e3

time: t2space: s2energy: e2

time: t1space: s1energy: e1

time: tspace: senergy: e

How Green are Java Best Practices? GreenDays | 2014-07-01 21 / 33

Page 61: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical MeasuresCanonical measure:

time: t3space: s3energy: e3

time: t2space: s2energy: e2

time: t1space: s1energy: e1

time: tspace: senergy: e

How Green are Java Best Practices? GreenDays | 2014-07-01 21 / 33

Page 62: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Clean and Canonical MeasuresCanonical measure:

time: t3space: s3energy: e3

time: t2space: s2energy: e2

time: t1space: s1energy: e1

time: tspace: senergy: e

error margin: 2%

How Green are Java Best Practices? GreenDays | 2014-07-01 21 / 33

Page 63: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Code MaturityCode Maturity

How many clean measures required for reliable results?

0 20 40 60 80 100 120

5

10

15

Measure Number

Relativ

eStandard

Deviatio

n

a set of 25 measures minimuma standard deviation less than 10%

How Green are Java Best Practices? GreenDays | 2014-07-01 22 / 33

Page 64: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Code MaturityCode Maturity

How many clean measures required for reliable results?

0 20 40 60 80 100 120

5

10

15

Measure Number

Relativ

eStandard

Deviatio

n

a set of 25 measures minimuma standard deviation less than 10%

How Green are Java Best Practices? GreenDays | 2014-07-01 22 / 33

Page 65: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Code MaturityCode Maturity

How many clean measures required for reliable results?

0 20 40 60 80 100 120

5

10

15

Measure Number

Relativ

eStandard

Deviatio

n

a set of 25 measures minimum

a standard deviation less than 10%

How Green are Java Best Practices? GreenDays | 2014-07-01 22 / 33

Page 66: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Code MaturityCode Maturity

How many clean measures required for reliable results?

0 20 40 60 80 100 120

5

10

15

Measure Number

Relativ

eStandard

Deviatio

n

a set of 25 measures minimuma standard deviation less than 10%

How Green are Java Best Practices? GreenDays | 2014-07-01 22 / 33

Page 67: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Results

Energy in nanojoules, time in nanosecondsMemory in kilobytesStandard Deviation on Energy

Replace Object Initialization by Literal Initialization

Rule Id Gree

nEn

ergy

Gray

Ener

gy

Gree

nT

ime

Gray

Tim

e

Gree

nM

emor

y

Gray

Mem

ory

Gree

nSt

dDev

Gray

StdD

ev

String 697 7885 842 7827 4136 36104 4.40% 8.14%Float 10311 10448 4736 4127 20032 20032 5.85% 6.58%Integer 685 9575 833 4591 4048 20032 5.21% 6.51%Boolean 683 6267 775 4741 4048 20032 4.77% 7.03%Char 695 33067 840 4595 4048 20032 5.04% 4.65%Double 10003 10210 5810 4270 28032 28032 5.58% 7.83%Long 669 8236 807 6066 4056 28032 2.89% 5.32%Short 680 7819 819 3846 4048 20031 4.87% 7.71%

How Green are Java Best Practices? GreenDays | 2014-07-01 23 / 33

Page 68: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Results

Replace Object Initialization by Literal Initialization

Rule Id Green Ene

rgy

GrayEne

rgy

Absolut

e Gain

Relativ

e Gain

String 697 7885 7188 91.16%Float 10311 10448 137 1.31%Integer 685 9575 8890 92.54%Boolean 683 6267 5584 89.10%Char 695 33067 32372 97.89%Double 10003 10210 207 2.02%Long 669 8236 7567 91.87%Short 680 7819 7139 91.30%

How Green are Java Best Practices? GreenDays | 2014-07-01 24 / 33

Page 69: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Results

Rules for loops

A Prefer integer loop countersB Avoid method loop conditionsC Prefer comparison-to-0 conditionsD Prefer first common condition

Id Gree

nEn

ergy

Gray

Ener

gy

Gree

nT

ime

Gray

Tim

e

Gree

nM

emor

y

Gray

Mem

ory

Gree

nSt

dDev

Gray

StdD

ev

A 82 98 4744 5931 16 16 8.66% 7.46%B 8376 8602 6181 6364 20056 20056 3.83% 6.14%C 89 284 4709 17367 16 16 5.09% 5.78%D 97 100 4934 5017 16 16 4.37% 4.60%

How Green are Java Best Practices? GreenDays | 2014-07-01 25 / 33

Page 70: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Results

Rules for loops

A Prefer integer loop countersB Avoid method loop conditionsC Prefer comparison-to-0 conditionsD Prefer first common condition

Id Green Ene

rgy

GrayEne

rgy

Absolut

e Gain

Relativ

e Gain

A 82 98 16 16.32%B 8376 8602 226 2.62%C 89 284 195 68.66%D 97 100 3 3.00%

How Green are Java Best Practices? GreenDays | 2014-07-01 25 / 33

Page 71: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

ResultsSet String Builder or Buffer Size

A String Buffer/Builder capacity initializationB String Buffer/Builder capacity settingC String Buffer/Builder length setting

Id Gree

nEn

ergy

Gray

Ener

gy

Gree

nT

ime

Gray

Tim

e

Gree

nM

emor

y

Gray

Mem

ory

Gree

nSt

dDev

Gray

StdD

ev

A 593 1053 38085 59111 52056 73784 7.11% 8.40%B 598 1053 38495 59111 52056 73784 7.86% 8.40%C 1211 1053 59111 70765 73784 104064 8.40% 9.40%A’ 378 899 19278 41088 52056 73784 8.27% 7.18%B’ 429 899 41088 51214 73784 104064 7.18% 5.84%C’ 1043 899 20976 41088 52056 73784 6.01% 7.18%

How Green are Java Best Practices? GreenDays | 2014-07-01 26 / 33

Page 72: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Results

Set String Builder or Buffer Size

A String Buffer/Builder capacity initializationB String Buffer/Builder capacity settingC String Buffer/Builder length setting

Id Green Ene

rgy

GrayEne

rgy

Absolut

e Gain

Relativ

e Gain

A 593 1053 460 43.68%B 598 1053 455 43.20%C 1211 1053 -158 -15.00%A’ 378 899 521 57.95%B’ 429 899 470 52.28%C’ 1043 899 -144 -16.01%

How Green are Java Best Practices? GreenDays | 2014-07-01 26 / 33

Page 73: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

1 Eco-Design and Best Practices

2 Formalizing Practices

3 Measuring Codes

4 Analyzing Measures, Codes, Practices

5 Eco-Design Indicators

Summary

Future

How Green are Java Best Practices? GreenDays | 2014-07-01 27 / 33

Page 74: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

How Green are Java Best Practices? GreenDays | 2014-07-01 28 / 33

Page 75: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

HypothesisBest Coding Practices ≈ Eco-Design Rules

174 formalized and measured rules

55% rules huge savings (more than 10%)20% rules few savings (between 3% and 10%)15% rules no savings (between -3% and 3%)10% rules some losses (less than -3%)

How Green are Java Best Practices? GreenDays | 2014-07-01 29 / 33

Page 76: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

HypothesisBest Coding Practices ≈ Eco-Design Rules

174 formalized and measured rules

55% rules huge savings (more than 10%)

20% rules few savings (between 3% and 10%)15% rules no savings (between -3% and 3%)10% rules some losses (less than -3%)

How Green are Java Best Practices? GreenDays | 2014-07-01 29 / 33

Page 77: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

HypothesisBest Coding Practices ≈ Eco-Design Rules

174 formalized and measured rules

55% rules huge savings (more than 10%)20% rules few savings (between 3% and 10%)

15% rules no savings (between -3% and 3%)10% rules some losses (less than -3%)

How Green are Java Best Practices? GreenDays | 2014-07-01 29 / 33

Page 78: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

HypothesisBest Coding Practices ≈ Eco-Design Rules

174 formalized and measured rules

55% rules huge savings (more than 10%)20% rules few savings (between 3% and 10%)15% rules no savings (between -3% and 3%)

10% rules some losses (less than -3%)

How Green are Java Best Practices? GreenDays | 2014-07-01 29 / 33

Page 79: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

HypothesisBest Coding Practices ≈ Eco-Design Rules

174 formalized and measured rules

55% rules huge savings (more than 10%)20% rules few savings (between 3% and 10%)15% rules no savings (between -3% and 3%)10% rules some losses (less than -3%)

How Green are Java Best Practices? GreenDays | 2014-07-01 29 / 33

Page 80: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

With The Way: 1 reliable measure system

hybrid physical and logical sensor managementcomplex client/server architecturefocused star schema database

robust automatic iterative processextensible programming API

reliable stable measure sets with few measures

How Green are Java Best Practices? GreenDays | 2014-07-01 30 / 33

Page 81: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

With The Way: 1 reliable measure system

hybrid physical and logical sensor management

complex client/server architecturefocused star schema database

robust automatic iterative processextensible programming API

reliable stable measure sets with few measures

How Green are Java Best Practices? GreenDays | 2014-07-01 30 / 33

Page 82: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

With The Way: 1 reliable measure system

hybrid physical and logical sensor managementcomplex client/server architecture

focused star schema databaserobust automatic iterative process

extensible programming APIreliable stable measure sets with few measures

How Green are Java Best Practices? GreenDays | 2014-07-01 30 / 33

Page 83: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

With The Way: 1 reliable measure system

hybrid physical and logical sensor managementcomplex client/server architecturefocused star schema database

robust automatic iterative processextensible programming API

reliable stable measure sets with few measures

How Green are Java Best Practices? GreenDays | 2014-07-01 30 / 33

Page 84: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

With The Way: 1 reliable measure system

hybrid physical and logical sensor managementcomplex client/server architecturefocused star schema database

robust automatic iterative process

extensible programming APIreliable stable measure sets with few measures

How Green are Java Best Practices? GreenDays | 2014-07-01 30 / 33

Page 85: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

With The Way: 1 reliable measure system

hybrid physical and logical sensor managementcomplex client/server architecturefocused star schema database

robust automatic iterative processextensible programming API

reliable stable measure sets with few measures

How Green are Java Best Practices? GreenDays | 2014-07-01 30 / 33

Page 86: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

With The Way: 1 reliable measure system

hybrid physical and logical sensor managementcomplex client/server architecturefocused star schema database

robust automatic iterative processextensible programming API

reliable stable measure sets with few measures

How Green are Java Best Practices? GreenDays | 2014-07-01 30 / 33

Page 87: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Eco-Design Indicators

• Jérôme Rocheteau, Virginie Gaillard, et Lamya Belhaj.How Green are Java Best Coding Practices?Proceedings of the 3rd International Conference on SmartGrids and Green IT Systems,pages 235–246.Barcelona, Espagne, Avril 2014.

How Green are Java Best Practices? GreenDays | 2014-07-01 31 / 33

Page 88: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?

2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments4 Rule indicators in different programming languages5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 89: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments4 Rule indicators in different programming languages5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 90: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savings

Relative savings3 Rule indicators in different environments4 Rule indicators in different programming languages5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 91: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments4 Rule indicators in different programming languages5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 92: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments

4 Rule indicators in different programming languages5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 93: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments4 Rule indicators in different programming languages

5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 94: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments4 Rule indicators in different programming languages5 Energy efficiency of different programming languages

6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 95: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments4 Rule indicators in different programming languages5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors

7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 96: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Future

1 Energy Efficiency Classes?2 Eco-Design Indicators?

Absolute savingsRelative savings

3 Rule indicators in different environments4 Rule indicators in different programming languages5 Energy efficiency of different programming languages6 Accuracy of different physical and/or logical sensors7 Energy and memory footprints of logical sensors

How Green are Java Best Practices? GreenDays | 2014-07-01 32 / 33

Page 97: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Thank you

How Green are Java Best Practices? GreenDays | 2014-07-01 33 / 33

Page 98: How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01

Data Model

How Green are Java Best Practices? GreenDays | 2014-07-01 33 / 33