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

Analyzer: Optimize area_to_pandas method #119

Merged
merged 1 commit into from
Sep 11, 2024
Merged

Conversation

EwoutH
Copy link
Contributor

@EwoutH EwoutH commented Sep 2, 2024

The area_to_pandas function has been optimized to significantly improve its execution speed.

  • Set lookups: Areas are converted to sets for O(1) membership checks, making the isin operations more efficient.
  • Vectorization: Replaced loop-based calculations with vectorized operations for total_travel_time and total_free_time, leveraging the power of numpy and pandas to perform these operations in bulk.
  • Single DataFrame access: Minimized repeated access to DataFrame columns, reducing the overhead of these operations.
  • Efficient grouping: Used unique() and nunique() for faster unique element counting.

In my testing of a large simulation, this sped up the function from ~75 seconds to ~2.5 seconds (about 30x).

The `area_to_pandas` function has been optimized to significantly improve its execution speed.

- Set lookups: Areas are converted to sets for O(1) membership checks, making the `isin` operations more efficient.
- Vectorization: Replaced loop-based calculations with vectorized operations for `total_travel_time` and `total_free_time`, leveraging the power of `numpy` and `pandas` to perform these operations in bulk.
- Single DataFrame access: Minimized repeated access to DataFrame columns, reducing the overhead of these operations.
- Efficient grouping: Used `unique()` and `nunique()` for faster unique element counting.
@EwoutH
Copy link
Contributor Author

EwoutH commented Sep 4, 2024

@toruseo I think this PR is relatively straightforward, it just makes this function faster without modifying it's behavior.

@toruseo toruseo merged commit 54229ac into toruseo:main Sep 11, 2024
6 checks passed
@EwoutH
Copy link
Contributor Author

EwoutH commented Sep 11, 2024

Thanks for merging! This PR was fully tested and validated to have identical output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants