-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AghilesAzzoug
changed the title
Resolve issue CRPYT404
Resolve issue CRPYT404 (Team 1.5)
Apr 6, 2023
Kudos, SonarCloud Quality Gate passed! |
MP-Aubay
added
🗃️ rule
rule improvment or rule development or bug
python
🏆 challenge2023 🏆
Work done during the ecoCode Challenge 2023
labels
Apr 7, 2023
Hi @AghilesAzzoug , please, could you :
... in order to merge this PR. |
dedece35
requested changes
May 7, 2023
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
dedece35
requested changes
May 8, 2023
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
dedece35
requested changes
May 16, 2023
...n/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
Outdated
Show resolved
Hide resolved
python-plugin/src/test/resources/checks/AvoidListComprehensionInIterations.py
Outdated
Show resolved
Hide resolved
…Iterations python rule
Kudos, SonarCloud Quality Gate passed! |
dedece35
approved these changes
May 16, 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
2. Co2 Emissions
Using CodeCarbon we get the following results:
For both metrics, the bigger the list, the greater is the gain is.
*Specs for experimentations:
On SonarQube
The render of an issue:
The render of the issue explanation: