Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issue CRPYT404 (Team 1.5) #152

Merged
merged 13 commits into from
May 16, 2023

Conversation

AghilesAzzoug
Copy link
Contributor

@AghilesAzzoug AghilesAzzoug commented Apr 6, 2023

Resolve of issue CRPYT404.

Summary

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.

Why it works?

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.
For more details on list comprehensions vs generator expressions, see Python documentation.

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

1. Memory usage:

memory_usage

2. Co2 Emissions

Using CodeCarbon we get the following results:

co2_emission

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

*Specs for experimentations:

  • 12th Gen Intel Core I7-12700H
  • 16 Gb RAM (4800 Mhz)
  • Windows 11 OS version 22H2
  • Python 3.9.15
  • memory_profiler==0.61.0 (for RAM experiments)
  • codecarbon==2.1.4 (for CO2 emissions)

On SonarQube

The render of an issue:
image

The render of the issue explanation:
image

@AghilesAzzoug AghilesAzzoug changed the title Resolve issue CRPYT404 Resolve issue CRPYT404 (Team 1.5) Apr 6, 2023
@sonarcloud
Copy link

sonarcloud bot commented Apr 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@MP-Aubay MP-Aubay added 🗃️ rule rule improvment or rule development or bug python 🏆 challenge2023 🏆 Work done during the ecoCode Challenge 2023 labels Apr 7, 2023
@dedece35
Copy link
Member

dedece35 commented May 7, 2023

Hi @AghilesAzzoug ,

please, could you :

  • resolve conflicts
  • take into account review notes
  • add some tests in python-test-project repository
  • modify CHANGELOG.md file
  • modify RULES.md file with your rule
  • correct code smells

... in order to merge this PR.

@dedece35 dedece35 added the 👀 👀 review done 👀 👀 review done - waiting for changes label May 7, 2023
@AghilesAzzoug
Copy link
Contributor Author

Hello @dedece35,

Thanks for reviewing this PR.

  • Your review notes were taken into account.
  • For the python-test-project, there's already a pending PR with test code for this issue (see #1).
  • CHANGELOG.md and RULES.md were updated.
  • I changed some parts of the code to adhere to SonarQube conventions.

@sonarcloud
Copy link

sonarcloud bot commented May 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

92.9% 92.9% Coverage
0.0% 0.0% Duplication

@dedece35 dedece35 merged commit 6d1724e into green-code-initiative:main May 16, 2023
@dedece35 dedece35 removed the 👀 👀 review done 👀 👀 review done - waiting for changes label May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗃️ rule rule improvment or rule development or bug 🏆 challenge2023 🏆 Work done during the ecoCode Challenge 2023 python
Projects
None yet
3 participants