Skip to content

Commit aac0e8e

Browse files
committed
apply requested changes
1 parent 906ea56 commit aac0e8e

File tree

10 files changed

+64
-35
lines changed

10 files changed

+64
-35
lines changed

src/main/rules/GCI10/python/GCI10.asciidoc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,33 @@ SVG images generated by common drawing softwares contains unnecessary data: calc
4040
</svg>
4141
----
4242

43-
==== Context
43+
== Relevance Analysis
44+
45+
The following results were obtained through local experiments.
46+
47+
=== Configuration
48+
49+
* SQLite Database: 5-6 GB
50+
* Processor: Intel(R) Core(TM) Ultra 5 135U, 2100 MHz, 12 cores, 14 logical processors
51+
* RAM: 16 GB
52+
* CO2 Emissions Measurement: Using CodeCarbon
53+
54+
=== Context
4455

4556
For example, by using SVGOMG, a tool for optimizing SVGs, we were able to reduce the file size from 22 KB to 11 KB, a 50% reduction. This is useful for page loading or data storage.
4657

4758
image::image.png[]
4859

49-
We decided to take some measurements using CodeCarbon. The emissions with the non-optimized file are 1.3928360831225074e-08, while the emissions with the optimized file are 9.68571752760373e-09, representing a 30% reduction in emissions.
60+
=== Test Execution
61+
62+
For this analysis, we simulated a process of manipulating these SVG files. The objective was to measure the impact of file size on CO2 emissions. We used an "optimized" SVG file and a "non-optimized" SVG file. The modification consisted of changing certain parts of the SVG and saving the final result.
63+
64+
=== Impact Analysis
65+
66+
image::output.png[]
67+
68+
=== Conclusion
69+
70+
The emissions with the non-optimized file are 1.3928360831225074e-08, while the emissions with the optimized file are 9.68571752760373e-09, representing a 30% reduction in emissions.
71+
72+
We recommend incorporating file optimization techniques as part of our standard development practices and exploring additional opportunities to reduce the environmental impact of our digital products.
16.9 KB
Loading

src/main/rules/GCI203/python/GCI203.asciidoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,18 @@ Or
8484
}
8585
----
8686

87-
88-
==== Our Analysis
87+
== Relevance Analysis
8988

9089
The following results were obtained through local experiments.
91-
===== Configuration
90+
91+
=== Configuration
92+
9293
* SQLite Database: 5-6 GB
9394
* Processor: Intel(R) Core(TM) Ultra 5 135U, 2100 MHz, 12 cores, 14 logical processors
9495
* RAM: 16 GB
9596
* CO2 Emissions Measurement: Using CodeCarbon
9697

97-
===== Context
98+
=== Context
9899

99100
This rule depends heavily on the context. For simple icon, the use of SVG is relevant because they will be lighter than their JPG counterparts. However, for more complex images, such as photographs, SVG will be heavier.
100101

@@ -106,6 +107,6 @@ This is because the vector format is not suitable for details, it is suitable fo
106107

107108
image::CNN_architecture.png[]
108109

109-
==== References
110+
=== References
110111
https://www.tensorflow.org/tutorials/images/cnn?hl=fr
111112
https://www.researchgate.net/publication/373715986_Convolutional_Neural_Network_CNN_The_architecture_and_applications

src/main/rules/GCI404/python/GCI404.asciidoc

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,30 @@ for var in (var2 for var2 in range(100)):
2121
...
2222
----
2323

24-
== Our Analysis
24+
== Relevance Analysis
2525

2626
The following results were obtained through local experiments.
2727

2828
Credit : https://github.com/AghilesAzzoug
2929

30-
=== Summary
31-
The use of generator expressions instead of list comprehensions in for-loops declaration can save RAM usage. It has multiple benefits like reducing CO2 emissions as well as releasing memory constraints on the hardware.
30+
=== Configuration
31+
32+
12th Gen Intel Core I7-12700H
33+
16 Gb RAM (4800 Mhz)
34+
Windows 11 OS version 22H2
35+
Python 3.9.15
36+
memory_profiler==0.61.0 (for RAM experiments)
37+
codecarbon==2.1.4 (for CO2 emissions)
3238

33-
=== Why it works?
39+
=== Context
40+
41+
The use of generator expressions instead of list comprehensions in for-loops declaration can save RAM usage. It has multiple benefits like reducing CO2 emissions as well as releasing memory constraints on the hardware.
3442
Python generators resemble lazy lists from other programming languages: when iterated over, they compute their values on the fly. They lack some list behaviors (indexing, len method, ...) but are memory-efficient, as they do not store each of their values in memory, unlike lists. Thus, when declared in a for-loop declaration, list comprehensions can be safely replaced with generator expressions.
3543
For more details on list comprehensions vs generator expressions, see Python documentation.
3644

37-
https://docs.python.org/3/howto/functional.html#generator-expressions-and-list-comprehensions
45+
46+
=== Impact Analysis
47+
3848

3949
Local experiments* on list comprehensions vs generator comprehensions gives the following results on:
4050

@@ -51,13 +61,12 @@ image::carbone.png[]
5161

5262
For both metrics, the bigger the list, the greater is the gain is.
5363

54-
*Specs for experimentations:*
64+
=== Conclusion
5565

56-
12th Gen Intel Core I7-12700H
57-
16 Gb RAM (4800 Mhz)
58-
Windows 11 OS version 22H2
59-
Python 3.9.15
60-
memory_profiler==0.61.0 (for RAM experiments)
61-
codecarbon==2.1.4 (for CO2 emissions)
66+
Our analysis clearly demonstrates that replacing list comprehensions with generator expressions in Python for-loops offers substantial benefits in terms of both memory efficiency and environmental impact. As the data size increases, the advantages become increasingly significant.
67+
68+
=== References
69+
70+
Source: https://github.com/green-code-initiative/creedengo-rules-specifications/pull/152
6271

63-
Source: https://github.com/green-code-initiative/creedengo-rules-specifications/pull/152
72+
https://docs.python.org/3/howto/functional.html#generator-expressions-and-list-comprehensions

src/main/rules/GCI7/python/GCI7.asciidoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ client.age # Récupérer l'attribut age
3434
client.age = 26 # Modifier l'attribut age
3535
----
3636

37-
== Our Analysis
37+
== Relevance Analysis
3838

3939
The following results were obtained through local experiments.
4040

@@ -67,9 +67,7 @@ class WithGetter():
6767

6868
=== Results
6969
image::tracking_1.png[]
70-
Another representation of the results is shown below:
7170

72-
image::tracking_2.png[]
7371

7472
For 100,000,000 iterations, the difference in CO2 equivalent emissions is 3.7*10^-6, which corresponds to 17 mm in equivalent emissions of a thermal car (see converter).
7573

@@ -82,6 +80,6 @@ Based on the results, we can conclude that using getters and setters in a class
8280

8381
It is important to keep in mind that for security or control reasons, the use of getters and setters may be necessary. In such cases, using the @property decorator can be a good alternative to traditional getters and setters. It allows restricting access to the attribute and adding logic when the attribute is accessed or modified. Performance is better than recreating getter and setter methods but not as good as direct attribute access.
8482

85-
== References
83+
=== References
8684
:hide-uri-scheme:
8785
https://www.datacamp.com/tutorial/property-getters-setters
-32.7 KB
Binary file not shown.

src/main/rules/GCI72/python/GCI72.asciidoc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,42 @@ def foo():
2323
...
2424
2525
----
26-
==== Our Analysis
26+
== Relevance Analysis
2727

2828
The following results were obtained through local experiments.
2929

30-
===== Configuration
30+
=== Configuration
3131
* SQLite Database: 5-6 GB
3232
* Processor: Intel(R) Core(TM) Ultra 5 135U, 2100 MHz, 12 cores, 14 logical processors
3333
* RAM: 16 GB
3434
* CO2 Emissions Measurement: Using CodeCarbon
3535

36-
===== Context
36+
=== Context
3737

3838
This practice can significantly degrade performance, especially when processing large datasets or making repetitive database calls. By opting for batch processing instead of executing queries in loops, developers can improve overall system efficiency and reduce the carbon footprint of their applications.
3939

40-
===== Test Execution
40+
=== Test Execution
4141

4242
The performance analysis was conducted by executing 1000 queries for both the non-compliant and compliant solutions. For the non-compliant solution, each query was executed individually within a loop. For the compliant solution, a batch query with the same 1000 queries was executed.
4343

44-
===== Impact Analysis
44+
=== Impact Analysis
4545

4646
[cols="1,1,1", options="header"]
4747
|===
4848
|Metric |Compliant Solution |Non-compliant Solution
4949
|Execution Time (seconds) |0.13391780853271484 |124.80779719352722
5050
|Carbon Emissions (kg CO2 eq) |6.0358009465562945e-06 |9.932707807019985e-05
51-
|Car Equivalent (mm) |27 |414
51+
|Car Equivalent (mm)* |27 |414
5252
|===
53-
(see converter).
5453

55-
:hide-uri-scheme:
56-
https://impactco2.fr/outils/comparateur
54+
*Converter: https://impactco2.fr/outils/comparateur
5755

58-
==== Conclusion
56+
=== Conclusion
5957

6058
The performance analysis conducted in this study only measures the execution time and carbon emissions of the Python code executing the queries. It does not include emissions due to database processing.
6159

6260
The results show that the compliant solution, which avoids SQL queries in loops, is more efficient in terms of execution time and carbon emissions. By adopting batch query processing and avoiding queries in loops, developers can improve application performance and reduce their carbon footprint. Developers are encouraged to use batch query processing whenever possible to improve application performance.
6361

64-
==== References
62+
=== References
6563
:hide-uri-scheme:
6664
https://blogs.oracle.com/sql/post/avoid-writing-sql-inside-loops
-1.97 KB
Loading
-2.02 KB
Loading
-3.69 KB
Loading

0 commit comments

Comments
 (0)