Character check performance #316

Closed
opened 2026-01-29 14:33:37 +00:00 by claunia · 1 comment
Owner

Originally created by @MihaZupan on GitHub (Aug 6, 2019).

@xoofx I've gone through and added optimizations such as the one I mentioned on Twitter to helper methods in CharHelper (there are other possible places where it could be used as well).

In a microbenchmark, performance improvements are amazing, around:
~10% for IsDigit, IsAlphaUpper
~2-4x for IsWhiteSpace, IsAlphaNumeric, IsPunctuation and other similar methods ...
~10x for IsEmailUsernameSpecialChar that was implemented as string.IndexOf

Sadly, in a real-world scenario, the difference is a 0-2% improvement.

@xoofx Do you think this is worth a PR?

Originally created by @MihaZupan on GitHub (Aug 6, 2019). @xoofx I've gone through and added optimizations such as the one [I mentioned on Twitter](https://twitter.com/_MihaZupan/status/1158106123788009472) to helper methods in `CharHelper` (there are other possible places where it could be used as well). In a microbenchmark, performance improvements are amazing, around: ~10% for `IsDigit`, `IsAlphaUpper` ~2-4x for `IsWhiteSpace`, `IsAlphaNumeric`, `IsPunctuation` and other similar methods ... ~10x for `IsEmailUsernameSpecialChar` that was implemented as `string.IndexOf` Sadly, in a real-world scenario, the difference is a 0-2% improvement. @xoofx Do you think this is worth a PR?
claunia added the questionenhancement labels 2026-01-29 14:33:37 +00:00
Author
Owner

@xoofx commented on GitHub (Oct 24, 2019):

Fixed by PR #377

@xoofx commented on GitHub (Oct 24, 2019): Fixed by PR #377
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#316