Skip to content

Simplify Capitalize Function Using ASCII Arithmetic for 5x Performance Boost #1

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

Merged
merged 1 commit into from
Aug 4, 2025

Conversation

Miladkhoshdel
Copy link
Owner

This PR refactors the capitalize function by replacing built-in string methods with direct ASCII arithmetic. This change simplifies the logic and significantly improves performance—benchmarked at approximately 5× faster than the original implementation.

Changes:

  • Removed dependency on string.ascii_lowercase and string.ascii_uppercase and Replaced string-based capitalization with manual ASCII offset
  • Reduced function complexity and branching
  • Added basic unit tests to ensure correctness

Benefits:

  • Eliminated external module dependency (string) for better portability and reduced overhead
  • Improved performance (5× faster in benchmarks)
  • More efficient implementation
  • Maintains readability and correctness

Checklist:

  • Code compiles without errors
  • Performance verified with benchmarks

@Miladkhoshdel Miladkhoshdel merged commit c02f1f1 into master Aug 4, 2025
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