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

use object lookup for convertDuration instead of switch #4002

Closed
wants to merge 4 commits into from

Conversation

retrogtx
Copy link
Contributor

Basically, now the function has better readablity and time complexity:
Object lookup: O(1) average case
Switch statement: O(n) in the worst case, where n is the number of cases

The object lookup is constant-time to the duration mapping, regardless of the input value. Thiss is WAY more efficient, especially for larger sets of cases. and switch statements look unecessarily long in this case.

@retrogtx retrogtx closed this Sep 13, 2024
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.

1 participant