You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve performance of integer formatting (#76726)
* Improve performance of integer formatting
1. The DivRem(..., 10) for each digit in the number ends up being the most expensive aspect of formatting. This employs a trick other formatting libraries use, which is to have a table for all the formatted values between 00 and 99, and to then DivRem(..., 100) to cut the number of operations in half, which for longer values is meaningful.
2. Avoids going through the digit counting path when we know at the call site it won't be needed.
3. Employs a branch-free, table-based lookup for CountDigits(ulong) to go with a similar approach added for uint.
* Address PR feedback (move license notice)
Copy file name to clipboardExpand all lines: src/libraries/System.Private.CoreLib/src/System/Buffers/Text/FormattingHelpers.CountDigits.cs
+43-45Lines changed: 43 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -52,60 +52,58 @@ public static int CountDigits(UInt128 value)
52
52
returndigits;
53
53
}
54
54
55
+
// Based on do_count_digits from https://github.com/fmtlib/fmt/blob/662adf4f33346ba9aba8b072194e319869ede54a/include/fmt/format.h#L1124
0 commit comments